jQuery – Looping through a collection of dropdowns

I have a collection of dropdowns dynamically generated by server code. Each of them have same set of values. My goal is to loop through all of them and see if at least one of the dropdowns is set to a specific value.

The id of each dropdown looks like:
id_enterprise_systems-0-type
id_enterprise_systems-1-type
id_enterprise_systems-2-type
id_enterprise_systems-3-type
id_enterprise_systems-4-type

Here’s a jQuery notation to loop through them all and check the selected value to set a global flag if a result is found.

var hosted = false;
$("select[id^='id_enterprise_systems-'][id$='-type']").each(function(){
	if ($(this).val() == 'H') {
		hosted = true;
	}
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s