I am trying to fire an alert depending on which value is selected from a <select> element using jQuery:
$("#optiontype").change( function () {
var option = $("#optiontype").val();
if(option.Contains("Forward")){
alert("forward selected");
}
});
The alert never fires whenever I choose ‘forward’ from the <select> element.
Change is the right event. The problem is that contains is not right in this case. Contains is for DOM traversal. What you need to use here is just a normal comparison like so:
Or if the string can contain more than just “forward”, check out indexOf: http://www.w3schools.com/jsref/jsref_indexof.asp