Reputation: 5454
I have a on change method defined for my drop-down as follows -
$("[name=engine]").change( function() {
var selectedIndex = $(this).val() ;
var selectedValue = $("#engine option[value=333]").text()
alert("Change..." + selectedIndex + " - "+ selectedValue);
});
Here instead of 333
, i want to substitute the value of selectedIndex
, how can I assign it to the option[Value= ??]
element?
Upvotes: 1
Views: 1574
Reputation: 1255
$("[name=engine]").change( function() {
var selectedIndex = $(this).val() ;
var selectedValue = $("#engine option[value="+selectedIndex +"]").text()
alert("Change..." + selectedIndex + " - "+ selectedValue);
});
did you try this?
Upvotes: 0
Reputation: 816462
The same way you create the alert
text: String concatenation.
$("#engine option[value='" + selectedIndex + "']").text()
Upvotes: 7