?
Solved

How to validate ALL dropdowns using JQuery

Posted on 2014-03-25
1
Medium Priority
?
415 Views
Last Modified: 2014-03-25
Hi

I have a x number of dropdown boxes on a page, they all have a class called "Cars", the 1st item on all  dropdown boxes has "-- Please select--"

Can someone please help me with some validation that will make sure ALL select boxes that have the class called "Cars" are gone through some validation i.e.

if ANY of the select boxes are set to the 1st item, in my case it is "-- Please select--", but I don't want to say if selectedText == "-- Please select--", as the text can be anything,
so it would be cool if its the selectedIndex.

thanks
0
Comment
Question by:mousemat24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39953066
Have a look at this:

$('.Cars').each(function() {
    if ( $(this).get(0).selectedIndex == 0 ) {
        console.log("No option selected");
    }
});

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question