jagku
asked on
jQuery - reusing change() function
Hello Experts,
If someone can give me advice on the following.
I have several selects:
<select id="search_1_unit">
...
</select>
<select id="search_1_m">
...
</select>
<select id="search_2_unit">
...
</select>
<select id="search_2_m">
...
</select>
<select id="search_3_unit">
...
</select>
<select id="search_3_m">
...
</select>
When the user selects a 'unit', I have an .change() jquery function that kicks in and dynamically populates
the search_1_m select.
ie
$('#search_1_unit').change (function( ) {
};
How do I rewrite this so that I don't have to write a
new function for each select.
ie I don't want to code:
$('#search_2_unit').change (function( ) {
};
$('#search_3_unit').change (function( ) {
};
etc
Many Thanks as always!
If someone can give me advice on the following.
I have several selects:
<select id="search_1_unit">
...
</select>
<select id="search_1_m">
...
</select>
<select id="search_2_unit">
...
</select>
<select id="search_2_m">
...
</select>
<select id="search_3_unit">
...
</select>
<select id="search_3_m">
...
</select>
When the user selects a 'unit', I have an .change() jquery function that kicks in and dynamically populates
the search_1_m select.
ie
$('#search_1_unit').change
};
How do I rewrite this so that I don't have to write a
new function for each select.
ie I don't want to code:
$('#search_2_unit').change
};
$('#search_3_unit').change
};
etc
Many Thanks as always!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks for the points!