Please clean js. There are 2 selekta, how to make it so that when choosing one selector in the 2nd, the value of the same index is automatically substituted, see

<form name="myform"> <select name="mysel1" style="width: 135px; onchange="onSel(this.form.mysel1)""> <option value="uno">uno</option> <option value="duo">duo</option> <option value="tre">tre</option> </select><br /> <select name="mysel2" style="width: 135px; onchange="onSel(this.form.mysel2)""> <option value="unos">unos</option> <option value="dos">dos</option> <option value="tres">tres</option> </select> </form> 

I explain: I chose duo (1st select), in the 2nd select the dos was substituted, if we chose a valid tres (2nd select), then in the 1st select the tre was selected. Navigate by index!

fiddle

half turned out:

 function onSel(dropdown){ selIndx = dropdown.selectedIndex; switch(dropdown.name) { case 'mysel1': document.form.mysel2.options[selIndx].selected == true; break; case 'mysel2': document.form.mysel1.options[selIndx].selected == true; break; } } 

Alas, the error hangs, can not find such a select.

    1 answer 1

    A working example is http://jsfiddle.net/Deonis/h2nMW/3/ . Not a form , but myform . Not selected == true , and selected = true

     function onSel(dropdown){ selIndx = dropdown.selectedIndex; switch(dropdown.name) { case 'mysel1': document.myform.mysel2.options[selIndx].selected = true; break; case 'mysel2': document.myform.mysel1.options[selIndx].selected = true; break; } } 

    or

     // ... document.myform.mysel2.options[selIndx].selected = 'selected'; // ... 
    • Oh, yes, thank you, I got into a bit of fun with ==. - Smash