user07
user07

Reputation: 670

how to validate drop down box using jquery or java script

I am using below code for validation of fields of my Dialog Box but if I have select-box then how we can validate it using same way as they have used for other text input fields ?

Link to access code from Jquery-UI site

http://jqueryui.com/dialog/#modal-form

In the same way I want to validate my select-box too.

Upvotes: 0

Views: 444

Answers (1)

Cosmin
Cosmin

Reputation: 2214

You can check length of selected options and dropdown's value, but this is nasty stuff and there are other ways to do it better and more elegant.

Example:

var $yourDropdown= $('#dropdownElement');
var $options= $('#dropdownElement option:selected');
if ($options.length == 0 || yourDropdown.val() == "")
{
}

More examples HERE, using jQuery Validate

Upvotes: 1

Related Questions