I have a form with 2 Submit buttons. One is for Approve the other is for Reject.
The HTML is:
<form action="test.php" method="post" name="sos_submit" id="sos_submit">
<input type="text" name="qty_indented" value="<?php echo $qty_indented ?>" id="qty_indented" readonly="readonly" />
<input type="text" name="qty_approved" value="<?php echo $qty_approved ?>" id="qty_approved" />
<input type="submit" name="da_approve" value="APPROVE" onclick="return submitForm(this)" />
<input type="submit" name="da_reject" value="REJECT" onclick="return submitForm(this)" />
</form>
And my submitForm(this) Function looks like:
<script>
function submitForm (button){
if (button.value == "APPROVE"){
var qty_approved = document.getElementById("qty_approved").value;
var qty_intended = document.getElementById("qty_indented").value;
if (qty_approved <= 0){
alert("Please Enter the Quantity for Approval!");
submitOK = "false";
}
else if(qty_approved >= qty_intended){
alert("Quantity Approved " + qty_approved + " Cannot be more than quantity intended " + qty_intended + " !");
submitOK = "false";
}
if (submitOK == "false") {
return false;
}
}
else{
confirm("Are you sure you want to REJECT the Voucher?");
}
}
</script>
Although its very simple code, but somehow not working properly.
Even though qty_approved is LESS than qty_indented, the if() statements are executing.
For example, if qty_approved = 5 and qty_indented = 10, then the code should submit the form, but it is NOT. It is showing: Quantity Approved 5 Cannot be more than quantity intended 10 !
Did I do anything wrong?
.valuereturns a string.qty_approved >= qty_intendedperforms string comparison.