Hi need to change the selected index of a when another has been changed.. Example: i have
<select id="selector">
<option>No 1</option>
<option>No 2</option>
</select>
<select id="selected">
<option>ONE</option>
<option>TWO</option>
</select>
now i want the $selected index to change when the #selector's index is changed.. like when i change to "No 2" the other combobox will change to "TWO". pardon me for newbie question but im new to jquery ^^
change( function(){ var index = this. selectedIndex; $('#selected option'). eq(index). prop('selected',true); });
To achieve this feat you can use various methods, two of those methods will be explained below. Used Function: val() function: It sets or returns the value attribute of the selected elements. attr() function: It sets or returns the attributes and values of the selected elements.
Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.
$('#selector').change(function() {
var idx = this.selectedIndex;
$("select#selected").prop('selectedIndex', idx);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With