jagamot
jagamot

Reputation: 5454

Simple jQuery assignment

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

Answers (2)

Rob
Rob

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

Felix Kling
Felix Kling

Reputation: 816462

The same way you create the alert text: String concatenation.

$("#engine option[value='" + selectedIndex + "']").text()

Upvotes: 7

Related Questions