views:

177

answers:

2

I have writen options to a <select> using something like

Id.innerHTML = "<option value='foo'>Foo</option>";

But on submission i get no value from the option? How can i correct this?

+1  A: 

with forms, if you show/hide dynamic fields, alot of times, you have to have hidden values to store the values in and then have your PHP (or whatever) look for the hidden field value, instead of the dynamic HTML value. It's a pain

Roy Rico
How do you get the hidden fields to by dynamic with the innerHTML?
Babiker
A: 

Thanks Roy i have thought about what you said and came up with the following:

function insert(){
               document.getElementById('text').value = document.getElementById('select').value;
    }

    function insertHTML(){
               document.getElementById('div').innerHTML = "<select id='select' onload=\"insert()\" onclick=\"insert()\"><option value='1'> 1 </option><option value='2'> 2 </option></select>";
    }



 <form method='post' action='http://localhost/test.php'&gt;
  <input type='button' value='insert' onclick="insertHTML(); insert();" >
  <div id='div' ></div>
  <input type='hidden' id='text' name='text'>
  <input type='submit' value='go'>
 </form>

Get input name instead of the name of the select.

Babiker