troubleshooting Question

jQuery - reusing change() function

Avatar of jagku
jagkuFlag for United States of America asked on
AJAX
2 Comments1 Solution266 ViewsLast Modified:
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!
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros