Avatar of jagku
jagkuFlag for United States of America

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!
AJAX

Avatar of undefined
Last Comment
leakim971
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Thanks for the points!
AJAX
AJAX

Asynchronous JavaScript and XML (AJAX) is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. With AJAX, web applications can send data to and retrieve from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. HTML and CSS can be used in combination to mark up and style information. The Document Object Model (DOM) is accessed with JavaScript to dynamically display and allow interaction with the information presented.

13K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo