tags:

views:

54

answers:

2

Hi all

I have a webpage containing input tags like the one below eg.

<input value='Cut' name='container_cut_button' type='submit/>
<input value='Copy' name='container_copy_button' type='submit/>

I want to put these into a dropdown, I was hoping it would be something simple like

<select onchange='submit()'>
   <option name='container_cut_button'>Cut</option>
   <option name='container_copy_button'>Copy</option>
</select>

but no such luck,

Anyone have any ideas about how this could be done?

Thanks in advance

+1  A: 

Use the "value" attribute of the options rather than their name.

<select name="action">
  <option value="cut_item">Cut</option>
  <option value="save_item">Save</option>
</select>

On the server, you'll check the value of the variable "action." It will be either "cut_item" or "save_item".

Jonathan Sampson
the problem is that the dropdown is going to have numerous different name attributes eg. container_cut_button (cuts content on the page) container_copy_button (copies content on the page)' so I had hoped it would be as easy as putting the name attributes into the <option> tags but no joy.
mark
Use "value" instead of "name" on the options.
Jonathan Sampson
A: 

I called a javascript function in the select tag ie. onchange="exec(value)", the function gets the select id and inserts the proper name attribute based on it value.

function exec(val){
  if(val=='cut'){
    document.getElementById("action").setAttribute("name", "cut")
  }
 }

This worked out ok

mark