Pages

Client side Drop down validation using jQuery

Client side Drop down validation using jQuery.




For the textbox MVC will write JavaScript

for Required, RegularExpression

& StringLength attributes but there is no built-in method to validate a

drop down menu, we need to define our own method.





First we need to define a method to

validate dropdown control and define rules for each dropdown controls.







To display your error message still you

need to defile required attribute on your property and include validation

summery on your page. E.g.







jQuery.validator.addMethod(



"selectNone",



function(value, element) {

if (element.value == "")

{







return false;







}







else return true;



},







"Please select an option."





);









$(document).ready(function() {







$("#form0").validate({







rules: {



"Title.TitleID": {







selectNone: true



},







"SecretQuestion.IntCode":{







selectNone: true







}







}







});



});



For more details click here or for more jQuery

validation click here