Solved

How to validate ALL dropdowns using JQuery

Posted on 2014-03-25
1
394 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
1 Comment
 
LVL 43

Accepted Solution

by:
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

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

821 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