Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-03
2
Medium Priority
?
371 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 2000 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

DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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)
Suggested Courses

705 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