The reason I asked about standing the test of time is that I previously used PHP echo to create a string and placed it into a div with .innerHTML, but modern browsers were not passing the value of the select box. (Went back and tested wit IE9 and the innerHTML version worked.)
file:js_selecttest.php
<form method="post" action='js_selecttest.php'>
<table>
<tr>
<td><input type="text" name="text_input" onClick="create_sel(document.getElementById('select_holder'),'class_date',op_array)">
<div id="select_holder">Filled by JS</div>
<br><input type="submit"></td>
</tr>
</table>
</form>
<script type="text/javascript">
function create_sel(container,sel_name,op_array)
{
var sel = document.createElement('select');
sel.name=sel_name;
populateList(op_array,sel);
container.innerHTML='';
container.appendChild(sel);
}
function populateList(op_array,sel_obj) // from http://www.webdeveloper.com/forum/showthread.php?206250#4
{
var arLen=op_array.length;
for(var i=0; i<arLen; i++)
{
sel_obj.options[i]=new Option(op_array[i], i);
sel_obj.options[i].value=op_array[i];
}
}
<?php
$op_array=array('Please Select','One','Two','Three','Four','Five','Six',);
?>
var op_array = <?php echo json_encode($op_array) ?>;
</script>
<?php
if($_POST)
{
var_dump($_POST);
}
?>
Would you have any suggestions or improvements?