SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing the selection in a <SELECT> list

    Ok,

    I've got a page which is part of a book ordering system. On this page, the user can select a book either by Title or ISBN. I have two drop-down <SELECT> menus which are populated with these two lists.

    So far so good.

    Now, when the user makes a choice from one, I need the other to automatically change to reflect the same choice. I have the onchange() set up ok, but how do I change the currently selected VALUE in the other list? I can easily set it up if I know that I want, say the fifth item selected, but how do I select the correct <OPTION> by value?

    As always, TIA
    Paul Simpson, BSc, MCNI, MCNE

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul, gee you seem to be here quite a bit

    Is this what you want?

    Code:
    <script type="text/javascript">
    <!--
    function doit(srcSel, destSel, ndx)
    {
      for (i = 0; i < destSel.length; i++)
    	 if (srcSel[ndx].value == destSel.options[i].value)
    		destSel.options[i].selected = true;
    }
    //-->
    </script>
    </head>
    <body>
    <form name="myform">
    <select name="a" onchange="doit(this, this.form['b'],this.selectedIndex)">
    <option value="1" selected>1</option>
    <option value="21">21</option>
    <option value="31">31</option>
    <option value="41">41</option>
    <option value="51">51</option>
    <option value="61">61</option>
    </select>
    <select name="b" onchange="doit(this, this.form['a'],this.selectedIndex)">
    <option value="61" selected>61</option>
    <option value="31">31</option>
    <option value="1">1</option>
    <option value="41">41</option>
    <option value="21">21</option>
    <option value="51">51</option>
    </select>
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Indeed you do! Trubble is, you are all just too helpful!

    Yep, bang on what I wanted. Thanks.
    Paul Simpson, BSc, MCNI, MCNE

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul,
    you are all just too helpful!
    Gee thanx

    Does that mean I can send St. Paul's a bill or get a teaching job there? (I promise not to scare those little English girls with my crusty, old, Brooklynese ways

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol
    Paul Simpson, BSc, MCNI, MCNE


Bookmarks

Posting Permissions

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