Here is a simple example of how to use a for loop to generate <option>'s for a select menu. This example also shows how to make a default <option> be selected:
Code:
<script type="text/javascript">
document.write('<select id="day">');
// write one selected option
document.write('<option value="" selected="selected">Day</option>');
// var num=1, as long as num is less than or equal to 31, num will increment
for(var num=1; num<=31; num++)
{
// write 31 options, with num as the value and text displayed.
// should add name attribute for server side
document.write('<option value="' + num + '">' + num + '</option>');
}
document.write('</select>');
</script>
Just a thought: it seems to me you might want to do this with a server side language like php, if you are using php for the form already? That way a user can turn off Javascript in their browser, and still see the generated form instead of pretty much nothing.
Bookmarks