Reputation: 1
Lets say I have
<select>
<option value="longSleeve">Long Sleeve</option>
<option value="shortSleeve">Short Sleeve</option>
</select>
how can I make my code do something when one is pressed. For example how can I make a variable set to 1 when 'Long Sleeve' is chosen and set the variable to 2 when 'Short Sleeve' is chosen and then if 'Long Sleeve' is chosen again set it back to 1.
Also pardon my noobyness at coding
Upvotes: 0
Views: 48
Reputation: 440
with jquery you can always add listeners like
.click()
to any tag on your html code, maybe you can add an id to that tag
<option id="firstOption" value="longSleeve">Long Sleeve</option>
and have something like
$("#firstOption").click(function(){
alert("click First option!");
});
hope this help : )
Upvotes: 0
Reputation: 63357
What you are looking for is the onchange
event handler, in jQuery
you can use .change()
or .on('change', handler)
like this:
var someVariable;
$('select').on('change', function(){
someVariable = this.selectedIndex + 1;
});
Upvotes: 1