0

I have a form and I'm collecting the entries of the form data and storing in my local storage. I'm able to validate the form (using jquery - validation.min.js plugin) and also creating a JSON.

But, I'm supposed to create JSON ONLY after validating the form with which I'm struck now.

NOTE: - The validation function is in my validation.js file. - The json creation function is within my HTML between script tag. I commented the submit handler part:

submitHandler: function(form) {
    form.submit();
}, 

thinking that the submit functions are colliding, but still the same result

I have a fiddle here FIDDLE

2 Answers 2

3

its display JSON form value because form submit event fired event validation throws error on submit event check for validation before prining JSON

if($('form').valid()){ 
  $('#result').text(JSON.stringify($('form').serializeObject()));    
}else{
 return false;
}
Sign up to request clarification or add additional context in comments.

Comments

1

I think you need this code

    $(function() {
        $('form').submit(function() {
            if($('#form').valid()){
                   $('#result').text(JSON.stringify($('form').serializeObject()));
                   return false;
            }

        });
    });

1 Comment

I'm glad I helped you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.