...

View Full Version : while loop for menu options- doesn't work



chesneil
06-10-2003, 01:33 AM
I'm writing a form which includes a pull-down for birth year. Rather than write:

<option value="1930">1930
......
......
<option value="2003">2003,

I have used a while loop. However, it doesn't seem to work. Can anyone please tell me why...? Going nuts...

Here's the code I'm using. Thanks.

Year <select name="byear">
<option selected value="none">-
<script language="JavaScript">
<!--
var count=1930;
while (count<2003)
{
document.write('<option value=\"'+count+'\">'+count);
count+=1;
}
//-->
</script>
</select>

cheesebagpipe
06-10-2003, 01:42 AM
Looks OK from here. Your drop-down is empty?

Might want to include closing tags:


Year <select name="byear">
<option selected value="none">-</option>
<script language="JavaScript">
<!--
var count = 1929;
while (count++<2002) document.write('<option value="'+count+'">'+count+'</option>');
//-->
</script>
</select>

chesneil
06-10-2003, 01:50 AM
Thanks a lot! It did the trick. Seems it needed the closing option tags. I don't know why because they aren't necessary on the other menus that I coded manually, line by line!?

Appreciate it!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum