i have many actions that should have the same function
<ul>
<li>
<select id="s1">
<option>Name</option>
<option>Year</option>
</select>
</li>
<li>
<select id="s2">
<option>Day</option>
<option>Month</option>
</select>
</li>
</ul>
and the jQuery calls for that selectors are
$(document).ready(function(){
$("#s1").on('change',function(){
var value = $("#s1").val();
alert(value);
});
$("#s2").on('change',function(){
var value = $("#s2").val();
alert(value);
});
});
look at the calls , they are the same , how can i make them as one call ?
code
this should help
if
'#s1‘ fires the function so$(this)refers to the select tag'#s1'so the statementvar value = $(this).val()will give u the selected option from the select'#s1'and the same thing for the select
'#s2'see this