0

I am trying to check if the commentform is filled in after submition, and only submit it when it is filled in.

I am using:

$('form').submit(function (e) {
    e.preventDefault();
    // Handle Checks
    $(this).submit();
});

But it's not submitting at all, any idea why this isn't working? Works on regular contact form in wordpress btw.

Thanks!

3
  • I guess there is a typo, it should be e.preventDefault() and not e.preventDefault. Can you please check? – Maruti Mohanty Oct 1 '13 at 11:22
  • @MarutiMohanty Yes. My bad. I already have that in code though. And it's not returning any warnings/errors. (JS) – user1410110 Oct 1 '13 at 11:25
  • Can't answer. But the answer is: I found an other way around it. I solved it replacing: $('form').submit(); With: $('form').unbind('submit'); $('#submit').click(); :) – user1410110 Oct 1 '13 at 11:43
0

Original Poster's answer in comments also worked for me, will share it here so this can have a solution.

Replace:

 $('form').submit(); 

With:

 $('form').unbind('submit'); $('#submit').click();

I used this to submit comments with JQuery with the ENTER key rather than clicking the button:

jQuery(document).ready(function($) {
$('#comment').keydown(function(event) {
    if (event.keyCode == 13) {//capture ENTER Key 
       $('form').unbind('submit'); $('#submit').click();
        return false;
       }
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.