JQuery iterate through current SELECT values

how do you iterate through just the current values of all selects, not the options?

i have tried variations of this:

$('select[name^="mydropdowns"] :selected').each(function() {
   if ($(this).val() != 'Test') {
      alert("Found.");
   }
 });

'Test' is the default selected value across a couple dropdown menus, yet this script never returns an alert. what am I doing wrong here?

Answers


Just iterate through selects

$('select[name^="mydropdowns"]').each(function() {
   if ($(this).val() != 'Test') {
      alert("Found.");
   }
});

val() is appliable to input/select/textarea elements and not to option element.

From jQuery doc: http://api.jquery.com/val/

The .val() method is primarily used to get the values of form elements such as input, select and textarea.


Need Your Help

rollback changes created by minitest unit test

ruby minitest

I'm writing a test case in Minitest that creates a database entry. After the test is run, all changes that the test did should be rolled back. What is a good way to achieve this?

Loop through hashmap to create a class instance with inside functions

java hashmap bukkit mcstats

I am making a bukkit plugin, and I am using an API called MCStats, to create the graph, you add Plotters like so...

Does having multiple work dimensions in a work group/item provides a speedup?

opencl gpgpu

In OpenCL, does having multiple work dimensions in a work group/item provides a speedup? If so, please point to some code or link.