Results 1 to 2 of 2

Thread: JS and setting selection box

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question JS and setting selection box

    I have a selection box with different ID. I save the data from this in a database using request.form(name of selection). My problem is that I wish to load the saved content to the webpage. How can I set the Selection when I have the ID? I can not use .selectedIndex because this is not related to the ID.

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I'm not sure if I've understood you properly, or if there is a quicker way to do it, but I'd use a loop. Try this for example:

    Code:
    <select onchange="for (var loopCounter = 0; loopCounter < this.length; loopCounter++) { if (this.options[loopCounter].id==['a']) { this.options[loopCounter].selected = true; break; } }">
      <option>1</option>
      <option id="a">2</option>
      <option>3</option>
    </select>

Posting Permissions

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



Click Here to Expand Forum to Full Width