Solved

My form validates but won't submit via ajax.. using jquery validate

Posted on 2014-04-14
3
850 Views
Last Modified: 2014-04-20
I open up the modal window with my form in it. Click 'Add' and the form validates fine but doesn't submit the url. Any idea what I'm missing?

<script type="text/javascript" charset="utf-8">	

$(function () {

$("#testdriveform").validate({

submitHandler: function (form) {
    $.ajax({
        type: "POST",
        url: "dplates/add/",
        data: $("#testdriveform").serialize()
    })
    .done(function (response) {
        if (response.success == 'success') {               
            alert('success');                       
        } else {
            alert('fail');
        }
    });
return false; 
},
        rules: {
            dPlate: {
                required: true,
                minlength: 6,
                maxlength: 6
            },
            rep_id: {
                required: true
            },
            firstName: {
                required: true
            },
            lastName: {
                required: true
            },
            phone: {
                required: true
            }
        }
    });

    $("#testdrive").dialog({
        autoOpen: false,
        width: 550,
        modal: true,
        buttons: {
            Add: function () {
                $("#testdriveform").submit();
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });

$( "#newdrive").live('click', function() {
$( "#testdrive" ).dialog( "open" );
id = $(this).data("id");
return false;
});
});
</script>

Open in new window

0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40000962
Are you sure you are not getting in javascript errors?

Check your console for errors - if there is an error it will stop execution of the form which could be preventing the submit.

Do you have a test link we can look at?

Otherwise - can you post more of your code so we can test it.
0
 
LVL 1

Accepted Solution

by:
tjyoung earned 0 total points
ID: 40001222
HI,
After a nights sleep: problem was the rule for dPlate. something to do with minlength and maxlength. Removed, submitted perfectly.
Have to check the docs on it.
Thanks for taking the time.
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 40011193
Simple error, found the problem.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question