How to validate ALL dropdowns using JQuery

Posted on 2014-03-25
Last Modified: 2014-03-25

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.

Question by:mousemat24
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 43

Accepted Solution

Chris Stanyon earned 500 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


Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

628 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