I am having this problem where a form is being submitted when it's not supposed to be submitted. This form is triggered by a button, however I'm clicking on a different button which performs a javascript math calculation... it seems that the onclick is being interpreted as a post?
How do I isolate a post eg. not submit the post unless I want to submit it?
this is the insert for php that is triggered by a different button.
<script>
function submitBill() {
var $id = "";
var $name = $('#name-of-bill').val();
var $cost = $('#cost-of-bill').val();
var $date = $('#due-date-of-bill').val();
$.post("insert-bill.php", {
'id':$id,
'name':$name,
'cost':$cost,
'date':$date }).done(function( data ) {
});
}
</script>
This is the button for the insert above
<button name="button-submit-new-bill" onclick="submitBill();">add bill</button>
This is the separate javascript math function that I'm trying to trigger.
// calculate weekly wage
function calculate() {
var hrs = document.getElementById('hours').value;
if(hrs>40){
var otHrs = hrs-40;
var regPay = 40*12;
var otPay = otHrs*18;
var pay = (regPay+otPay)*0.82;
var payM = +(Math.round(pay + "e+2") + "e-2");
alert(payM);
}else{
var pay = hrs*12*0.82;
var payM = +(Math.round(pay + "e+2") + "e-2");
alert(payM);
}
}
This is the button that triggers the php insert above.
<button name="calculate" onclick="calculate();">go</button>