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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Create drop down menus with loop?

    I am trying to create a drop down menu using a for loop so that all the values inside the menu are the same but the select name will be different for each menu. What am I doing wrong with the syntax?

    <script language="javascript">

    for (var i = 0; i < 3; i++){

    document.write('<td width="4%"><div align="center" class="style9"><span class="style1">'In'</span></div></td>');

    document.write('<td width=""><select id = "state[i]" name = "state[i]" class="style2" onfocus="checkState(this)">
    <option value="California">'California'</option>
    <option value="Florida">'Florida'</option>
    <option value="Texas">'Texas'</option>
    </select></td></td>');
    }

    </script>

    Please take note that I am trying to name each select state1, state2, and state3 by using state[i] for the name and id. Will this work this way and am I using the double quotes and single quotes correctly? Thanks!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    document.write('<td width=""><select id = "state'+(i+1)+'" name = "state'+(i+1)+'" class="style2" onfocus="checkState(this)"><option value="California">California</option><option value="Florida">Florida</option><option value="Texas">Texas</option></select></td>');

    There should be no line breaks inside the string.


  •  

    Posting Permissions

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