very simple problem (i guess...)

Discussion in 'JavaScript' started by falcondriver, Apr 28, 2006.

  1. #1
    hi,

    i never did javascript before (im the php/sql guy...), so im not sure whats wrong here, maybe just a syntax error. its about 2 option-fields (startcountry, endcountry), if someone changes "startcountry" then i want the same value selected as "endcountry". the user can still change "endcountry" without affecting any other fields, so no action required here.

    thats what i have so far, i have no idea whats wrong:

    
    <html><body>
    <form name="rideboard" action="">
    <select name="startcountry" id="startcountry" onchange="update(this.form.startcountry.value)">
    <option value="1">sunny country</option>
    <option value="2">backward country</option>
    <option value="3">nerverheardabout country</option>
    </select>
    <select name="endcountry">
    <option value="1">sunny country</option>
    <option value="2">backward country</option>
    <option value="3">nerverheardabout country</option>
    </select>
    </form>
    <script type="text/javascript">
    function update(newvalue) {
    	alert(newvalue);
        document.rideboard.endcountry.value = newvalue;
      }
    }
    </script>
    </body></html>
    
    HTML:
    this alert() is just for testing, dosnt has to be there...
     
    falcondriver, Apr 28, 2006 IP
  2. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have an extra bracket in your function.

    function update(newvalue) {
    alert(newvalue);
    document.rideboard.endcountry.value = newvalue;
    // extra bracket here }
    }

    Next time you're having problems in javascript, try looking at the JavaScript console in Firefox.
     
    torunforever, Apr 28, 2006 IP
    falcondriver likes this.