Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Submitting form Twice
    primarykey
    data
    text
    <p>I know this question has been answered a few hundred times, but I have run through a load of the potential solutons, but none of them seem to work in my instance.</p> <p>Below is my form and code for submitting the form. It fires off to a PHP script. Now I know the script itself isn't the cause of the submit, as I've tried the form manually and it only submits once.</p> <p>The 1st part of the jQuery code relates to opening up a lightbox and pulling values from the table underneath, I have included it in case for whatever reason it is a potential problem.</p> <p>jQuery Code:</p> <pre><code>$(document).ready(function(){ $('.form_error').hide(); $('a.launch-1').click(function() { var launcher = $(this).attr('id'), launcher = launcher.split('_'); launcher, launcher[1], $('td .'+launcher[1]); $('.'+launcher[1]).each(function(){ var field = $(this).attr('data-name'), fieldValue = $(this).html(); if(field === 'InvoiceID'){ $("#previouspaymentsload").load("functions/invoicing_payments_received.php?invoice="+fieldValue, null, function() { $("#previouspaymentsloader").hide(); }); } else if(field === 'InvoiceNumber'){ $("#addinvoicenum").html(fieldValue); } $('#'+field).val(fieldValue); }); }); $("#addpayment_submit").click(function(event) { $('.form_error').hide(); var amount = $("input#amount").val(); if (amount == "") { $("#amount_error").show(); $("input#amount").focus(); return false; } date = $("input#date").val(); if (date == "") { $("#date_error").show(); $("input#date").focus(); return false; } credit = $("input#credit").val(); invoiceID = $("input#InvoiceID").val(); by = $("input#by").val(); dataString = 'amount='+ amount + '&amp;date=' + date + '&amp;credit=' + credit + '&amp;InvoiceID=' + invoiceID + '&amp;by=' + by; $.ajax({ type: "POST", url: "functions/invoicing_payments_make.php", data: dataString, success: function(result) { if(result == 1){ $('#payment_window_message_success').fadeIn(300); $('#payment_window_message_success').delay(5000).fadeOut(700); return false; } else { $('#payment_window_message_error_mes').html(result); $('#payment_window_message_error').fadeIn(300); $('#payment_window_message_error').delay(5000).fadeOut(700); return false; } }, error: function() { $('#payment_window_message_error_mes').html("An error occured, form was not submitted"); $('#payment_window_message_error').fadeIn(300); $('#payment_window_message_error').delay(5000).fadeOut(700); } }); return false; }); }); </code></pre> <p>Here is the html form:</p> <pre><code>&lt;div id="makepayment_form"&gt; &lt;form name="payment" id="payment" class="halfboxform"&gt; &lt;input type="hidden" name="InvoiceID" id="InvoiceID" /&gt; &lt;input type="hidden" name="by" id="by" value="&lt;?php echo $userInfo_ID; ?&gt;" /&gt; &lt;fieldset&gt; &lt;label for="amount" class="label"&gt;Amount:&lt;/label&gt; &lt;input type="text" id="amount" name="amount" value="0.00" /&gt; &lt;p class="form_error clearb red input" id="amount_error"&gt;This field is required.&lt;/p&gt; &lt;label for="credit" class="label"&gt;Credit:&lt;/label&gt; &lt;input type="text" id="credit" name="credit" /&gt; &lt;label for="amount" class="label"&gt;Date:&lt;/label&gt; &lt;input type="text" id="date" name="date" /&gt; &lt;p class="form_error clearb red input" id="date_error"&gt;This field is required.&lt;/p&gt; &lt;/fieldset&gt; &lt;input type="submit" class="submit" value="Add Payment" id="addpayment_submit"&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Hope someone can help as its driving me crazy. Thanks.</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.
 

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