Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Jquery .validate function not working properly.

For the very first time on page load, if the submit button is clicked, nothing is being validated, even though the form inputs are empty. The form gets submitted even though the validate function is called in $(document).ready(function())

i have a form where all the input types are defined in a div name e.g., 'targetListDiv'

$("#saveTargetList").on('click', function(e) {

if (!$("#targetListDiv").validate()) { // Not Valid
            return false;
        } 
$.ajax({

    url : 'example.htm',
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType : 'json',
    data: JSON.stringify(data),
    success: function (text) { 

               alert(text);
            }, error: function(text){

                alert(text);
  });

always the form gets submitted even if there is an error.

No errors are being displayed to the customer. But if i click on a text box and lets say, the min length is 7, and i enter only 5 characters, then the error is being displayed.

Please let me know if there is a way to prevent this.

Thanks.

share|improve this question
1  
Please add your html code also –  Muthukumar Jul 12 '13 at 12:33
    
e.preventDefault() also will solve your problem –  Thirumalai murugan Jul 12 '13 at 12:34
    
the jQuery .validate() is a plugin not part of jQuery "normal" .js file, so you neede that .js also. (Just in case its that the problem) –  Sergio Jul 12 '13 at 12:35
    
Thanks guys. I just found out the issue. I had missed the "name" attribute in all the input fields which was causing the issue. After including the name parameter, the issue was resolved. The validate function started working properly. –  ram Jul 12 '13 at 12:37
    
@ram you could also answer and close it –  willome Jul 12 '13 at 12:50

1 Answer 1

up vote 0 down vote accepted

I had missed the "name" attribute in input fields hence the validate function was not working properly.

including the "name" attribute resolved the issue.

Thanks guys!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.