Hello and welcome to our community! Is this your first visit?
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
    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>


    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. #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Thanked 257 Times in 253 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.
    Last edited by glenngv; 03-24-2004 at 09:32 AM.


Posting Permissions

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