Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit Form after validation buttons has to be hit twice
    primarykey
    data
    text
    <p>I don't have access to the php file so I have to validate using JavaScript. I decided to use jQuery with it. I do this:</p> <pre><code>$(document).ready(function(){ $('#targetForm').submit(function(e){ e.preventDefault(); closeOpenBoxes(); }); }); function closeOpenBoxes(){ if($('.missingBox:visible').length &gt; 0){ $('.missingBox:visible').slideUp('fast', function(){ validateForm(); }); } else{ validateForm(); } } function validateForm(){ if($('#first_name').val() == ''){ $('#firstNameBox').slideDown(); } else{ if($('#last_name').val() == ''){ $('#lastNameBox').slideDown(); } else{ if($('#company').val() == ''){ $('#companyBox').slideDown(); } else{ if($('#country').val() == ''){ $('#countryBox').slideDown(); } else{ if($('#email').val() == ''){ $('#emailBox').slideDown(); } else{ $('#targetForm').unbind(); $('#targetForm').submit(); } } } } } } </code></pre> <p>It works, but for the form to actually submit after validation, you have to hit the submit button twice. I tried a few different things like adding <code>return true</code> to the end of my functions and even putting a timeout on the submit so the <code>e.preventDefault()</code> would completely unbind before before the <code>submit</code> would fire after validation like this and it still didn't work:</p> <pre><code>$('#targetForm').unbind(); setTimeout(function(){$('#targetForm').submit()},1000); </code></pre> <p>I made a fiddle: <a href="http://jsfiddle.net/uXg3R/1/" rel="nofollow">http://jsfiddle.net/uXg3R/1/</a> I'm not sure what I'm missing any help would be awesome</p>
    singulars
    1. This table or related slice is empty.
    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