Solved

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

Posted on 2013-06-03
2
364 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
[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 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
How do I split a variable to newline 2 44
boostsrap 1 35
CSS (jquiry mobile) question 3 34
Woo-commerce gallery not working properly 12 40
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…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
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…

734 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