Solved

Trying to use jquery validation plugin on click, kind of works but continues on

Posted on 2013-06-03
2
340 Views
Last Modified: 2013-06-04
Hi,
I have a form that when I submit as shown below, the subject rule error shows for a brief second before it continues on with the submission. It doesn't stop the form from submitting. Can't figure out what to do...bit extra code in there for the CKEditor. No errors showing up in firebug, all works, submits, except if I intentionally leave the subject field blank, I see the error for a brief second and it keeps going.

<script type="text/javascript">

$( "#save-exit" ).live('click', function() {

	$("#emailsettings").validate({
		rules: {
		subject: {required: true}
		}
		});
        
        window.onbeforeunload = 'NULL';
        
        var content = {
            html_HEAD:CKEDITOR.instances.html_HEAD.getData(),
            html_MAIN:CKEDITOR.instances.html_MAIN.getData(),
            title: $('input[name=title]').val(),
            subject: $('input[name=subject]').val(),
            from_name: $('input[name=from_name]').val(),
            from_email: $('input[name=from_email]').val(),
            scheduled: $('input[name=scheduled]').val(),
            id: $("#id").val(),
            cid: $("#cid").val(),
            template: $("select[name='templates']").val(),
            sponsor_id: $("select[name='sponsor']").val(),
        }

        $.ajax({
            url: 'email/save',
            type: 'post',
            success: function (data) {
            window.location.href = '/app/email';
            },
            data: content
        });
    });
   
</script>

Open in new window

0
Comment
Question by:tjyoung
2 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 39217487
when you submit and see the error msg briefly :
it's validating but you haven't told it to submit only if validation gives a thumbs up ...

      
if($("#emailsettings").validate().form()) {      
      $.ajax({
            url: 'email/save',
            type: 'post',
            data: content,
            success: function (data) {
                  window.location.href = '/app/email';
            }            
      });
}      
return false;      

stick this into your code (replace your existing ajax) and it should be good to go ...
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 39218516
Perfect. Thanks for clarifying!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now