SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple SELECT question!

    Ok, I have three different SELECTs on my page

    Code:
     
    <select name="one">
    <option value="Select one">Select one</option>
    <option value="cool">cool</option>
    </select>
     
    <select name="two">
    <option value="Select two">Select two</option>
    <option value="cooler">cooler</option>
    </select>
     
    <select name="three">
    <option value="Select three">Select three</option>
    <option value="coolest">coolest</option>
    </select>
    I'd just like to know how to make this scenario work with java_script_:
    The person select cool for the first one, then cooler for the second, but if he selects coolest for the third, I want the first and second selects to reset back for Select one & Select two respectively.

    Basicly, if he selects anything in the third select I want the two first selects to default back to the default.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's say your form is named "form_1"

    Code:
    function revertSelect() {
       var selectOne = document.form_1.one;
       var selectTwo = document.form_1.two;
    
       // Value of the third select
       var s3v = document.form_1.three.value;
    
       if (s3v == "coolest") {
         selectOne.value = 'Select one';
         selectTwo.value = 'Select two';
       }
    }
    Code:
    <form name="form_1">
    
     <select name="one">
      <option value="Select one">Select one</option>
      <option value="cool">cool</option>
     </select>
     
     <select name="two">
      <option value="Select two">Select two</option>
      <option value="cooler">cooler</option>
     </select>
     
     <select name="three" onChange="revertSelect();">
      <option value="Select three">Select three</option>
      <option value="coolest">coolest</option>
     </select>
     
    </form>
    This will revert select one and two back to the "Select one" and "Select two" if select three is changed to "coolest".

    Note: replace the three appearances of "form_1" in the function with whatever your form is named.
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot mate!
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches


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
  •