JQuery Validation On Select Box Not Working July 22, 2022 Post a Comment I am using jQuery validation plugin for client side validation, but my validation does not work on my select box. HTML Solution 1: A simple way to fix this problem is to give the non valid option the value of "". Then simply call validate on your form and it will not submit when "Choose" is selected. HTML <form id="formid"> <select name="select" class="required"> <option value="">Choose</option> <option value="child">test2</option> </select> <input type="submit" /> </form> Copy JavaScript $("#formid").validate(); Copy Demo Solution 2: Although this probably works with some of the aforementioned methods,if you're looking to use a custom validation function, you should use addMethod as documented here: http://docs.jquery.com/Plugins/Validation/Validator/addMethod So you would first add the method through something like $.validator.addMethod("requiredSelect", function(element) { return ( $("#select").val() !='-1' ); }, "You must select an option."); Copy Then simply assign the validator with $("#formid").validate({ rules: { select: { requiredSelect : true } } }); Copy Solution 3: instead of: $("#select").val() try: $("#select :selected").val() $("#select").val() returns all the option values instead of the selected one. Here, my assumption is that you want to check if the user has chosen the option -1 when the control report-crime is validated. Solution 4: by default <option value="">Choose</option> works with required: true Solution 5: There is missing name attribute in your select element. In my case that was the issue since the jQuery Validatation Plugin looks for the name not id while validating. Share Post a Comment for "JQuery Validation On Select Box Not Working"
Post a Comment for "JQuery Validation On Select Box Not Working"