Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validate select box

Tags:

I am using jQuery Validation Plugin for form validation and I am not able to validate list/select box

<select id="select">
 <option value="-1">Choose an option</option>
 <option value="1">One</option>
 <option value="2">Two</option>
 <option value="3">Three</option>
</select>

Now, I want to make sure that the user selects anything but "Choose an option" (which is the default one, and has value as -1). So that it won't validate if you choose the first option. How can this be done?

like image 498
I-M-JM Avatar asked Dec 06 '10 07:12

I-M-JM


People also ask

How do you validate a select box?

Validate (Check) HTML Select DropDownList using jQuery Inside the jQuery OnClick event handler, the HTML Select DropDownList object is referenced and if the selected value matches the value of the default item then an error message is displayed using JavaScript alert message box.

What is jQuery validate unobtrusive?

Unobtrusive Validation means without writing a lot of validation code, you can perform simple client-side validation by adding the suitable attributes and including the suitable script files. These unobtrusive validation libraries need to be added: jquery.validate.min.js.


1 Answers

Put <option value="">Choose an option</option> as blank rather than -1

using jquery validation

rules: {                      
                select: "required"
}
like image 150
Vicky Avatar answered Sep 18 '22 15:09

Vicky