php - jQuery Submitting form Twice -


i know question has been answered few hundred times, have run through load of potential solutons, none of them seem work in instance.

below form , code submitting form. fires off php script. know script isn't cause of submit, i've tried form manually , submits once.

the 1st part of jquery code relates opening lightbox , pulling values table underneath, have included in case whatever reason potential problem.

jquery 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();          = $("input#by").val();          datastring = 'amount='+ amount + '&date=' + date + '&credit=' + credit + '&invoiceid=' + invoiceid + '&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 not submitted");                 $('#payment_window_message_error').fadein(300);                 $('#payment_window_message_error').delay(5000).fadeout(700);             }         });         return false;     }); }); 

here html form:

<div id="makepayment_form">   <form name="payment" id="payment" class="halfboxform">     <input type="hidden" name="invoiceid" id="invoiceid" />     <input type="hidden" name="by" id="by" value="<?php echo $userinfo_id; ?>" />     <fieldset>       <label for="amount" class="label">amount:</label>       <input type="text" id="amount" name="amount" value="0.00" />       <p class="form_error clearb red input" id="amount_error">this field required.</p>        <label for="credit" class="label">credit:</label>       <input type="text" id="credit" name="credit" />       <label for="amount" class="label">date:</label>       <input type="text" id="date" name="date" />       <p class="form_error clearb red input" id="date_error">this field required.</p>     </fieldset>     <input type="submit" class="submit" value="add payment" id="addpayment_submit">   </form> </div> 

hope can driving me crazy. thanks.

some times have not prevent default behauviour handling event, prevent executing downstream chain of event handlers. can done calling event.stopimmediatepropagation() in addition event.preventdefault().

example code:

$("#addpayment_submit").on('submit', function(event) {   event.preventdefault();   event.stopimmediatepropagation(); }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -