?
Solved

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

Posted on 2014-04-14
3
Medium Priority
?
859 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
  • 2
3 Comments
 
LVL 60

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…
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…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 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