Solved

How to validate ALL dropdowns using JQuery

Posted on 2014-03-25
1
388 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 42

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now