Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX and jQuery validate issue
    primarykey
    data
    text
    <p>So I got stuck in this dead end. I have AJAX script and jQuery Validation plug-in. With this script, when my page loads empty contact form automatically submits on itself. If I move or add <code>$('#submit').click(function () {</code> over AJAX script part, right below <code>$(document).ready(function() {</code> then on submit it ignores my validation form.</p> <p>Any help will be greatly appreciated.</p> <pre><code>&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'&gt;&lt;/script&gt; &lt;script type='text/javascript' src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js'&gt;&lt;/script&gt; &lt;script&gt; var captcha_a = Math.ceil(Math.random() * 10); var captcha_b = Math.ceil(Math.random() * 10); var captcha_c = captcha_a + captcha_b; function generate_captcha(id){ var id = (id) ? id : 'lcaptcha'; $("#"+id).html(captcha_a + " + " + captcha_b + " = "); } $(document).ready(function() { $('#submit').click(function () { jQuery.validator.addMethod("math", function(value, element, params) { return this.optional(element) || value == params[0] + params[1]; }, jQuery.format("Please enter the correct value for {0} + {1}") ); $("#commentform").validate({ rules: { captcha: { math: [captcha_a, captcha_b] } } }); }); }) &lt;/script&gt; &lt;script&gt; $(document).ready(function() { var name = $('input[name=name]'); var phone = $('input[name=phone]'); var email = $('input[name=email]'); var reason = $('select[name=reason]'); var info = $('textarea[name=info]'); var data = 'name=' + name.val() + '&amp;phone=' + phone.val() + '&amp;email=' + email.val() +'&amp;reason=' + reason.val() + '&amp;info=' + encodeURIComponent(info.val()); $('.loading').show(); $.ajax({ url: "ajaxformtoemail.php", type: "GET", data: data, cache: false, success: function (html) { if (html==1) { $('.form').fadeOut('slow'); $('.done').fadeIn('slow'); } else alert('Sorry, unexpected error. Please try again later.'); } }); return false; }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload