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

Ruby Trying to get a 3 line return

ruby newline

Hi I'm trying to get the program to return all three lines on top of one another when a 5 is entered. It's only returning the third line. This is Ruby. (My first time trying it)

Using functions with multiple arguments with lapply in Rcpp

c++ rcpp lapply

I am trying to use Rcpp lapply function with functions with multiple arguments.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.