views:

326

answers:

2

I have 2 comboboxs "combo1" and "combo2",

if i select any value in combo1, i need that same value in combo2 as "selected" by javascript

<html>
    <head>
     <title>combo</title>

    </head>
    <body>
     <form name="testForm" action="" method="post">
      <select name="combo1">
                <option value="1">option 1</option>
       <option value="2">option 2</option>
       <option value="3">option 3</option>
      </select><br /><br />
      <select name="combo2">
      <option value="1">option 1</option>
      <option value="2">option 2</option>
      <option value="3">option 3</option>
      </select>
     </form>
    </body>
</html>

Hoping your help

+1  A: 

onChange() can help <select name="combo1" onChange="changeCombo2(...)">

LarsOn
+1  A: 
<script type='text/javascript'>
    window.onload = function() { BindEvent(); }

    function BindEvent()
    {
        var elemToBind = document.getElementById ( "cmb1" );
        cmb1.onchange = function () { SetSel ( this ); }
    }
    function SetSel(elem)
    {
        var secondCombo = document.getElementById ( "cmb2" );
        secondCombo.value = elem.value;   
    }
</script>
<body>
    <select id="cmb1">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
    <select id="cmb2">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
</body>
rahul
tks for ur answer
Alex
@Alex: spk in whole sentences plz.
Crescent Fresh