Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If this is actually the code you're using, you seem to have wrapped your <strong>onclick</strong> function around the <strong>$.click</strong> event-adding function:</p> <pre><code>function feedback_form_submit() { $(function() { // This adds a click handler each time you run feedback_form_submit(): $(".submit").click(function() { // ... // return false; }); }); } </code></pre> <p>When I tried this on jsFiddle.net, I clicked Submit the first time and nothing happened, then the second time it posted twice, the third click posted three times, etc.</p> <p>You should just keep it simple: take out the <strong>onclick</strong> attribute:</p> <pre><code>&lt;input type="button" value="Submit" class="submit" /&gt; </code></pre> <p>and remove the feedback_form_submit() wrapper:</p> <pre><code>$(function() { $(".submit").click(function() { // ... // return false; }); }); </code></pre> <p>This way the <strong>$.click</strong> handler function will be applied just once, when the page loads, and will only run once when <em>Submit</em> is clicked.</p> <p><strong>EDIT:</strong> </p> <p>If your form is loaded via AJAX in a popup DIV, you have two options:</p> <p>Keep your <strong>onclick</strong> but remove the <strong>$.click</strong> wrapper instead:</p> <pre><code>function feedback_form_submit() { // ... // } </code></pre> <p>and</p> <pre><code>&lt;input type="button" value="Submit" class="submit" onclick="feedback_form_submit()" /&gt; </code></pre> <p>Note that you only need to return false if you're using <strong>&lt;input type="submit" ... &gt;</strong>; when using <strong>&lt;input type="button" ... &gt;</strong>, the browser does not watch the return value of <strong>onclick</strong> to determine whether to post the form or not. (The return value may affect event propagation of the click, however ...).</p> <p>Alternatively, you can use jQuery's <strong>$.live</strong> function:</p> <pre><code>$(function() { $('.submit').live('click',function() { // ... // }); }); </code></pre> <p>and</p> <pre><code>&lt;input type="button" value="Submit" class="submit" /&gt; </code></pre> <p>This has the effect of watching for new DOM elements as they are added dynamically; in your case, new <strong>class="submit"</strong> elements.</p>
 

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