Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while loop for menu options- doesn't work

    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>

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks OK from here. Your drop-down is empty?

    Might want to include closing tags:
    Code:
    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>

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •