[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-04-14
3
Medium Priority
?
856 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 59

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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

650 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