javascript - Submit Form When User Clicks OK on Confirm Box -
i have javascript in html form runs when user clicks submit button. displays total price users order , has buttons "ok" , "cancel". want form submitted when user clicks "ok", not submitted if user clicks "cancel". submits form when either button pressed. how keep submitting form if "cancel" clicked?
this short script:
<script type="text/javascript"> function calculate() { var gprice var aprice var sprice var total gprice = document.getelementbyid("grapeorderquantity").value * 4.0; aprice = document.getelementbyid("appleorderquantity").value * 3.0; sprice = document.getelementbyid("strbryorderquantity").value * 3.5; total = (gprice + aprice + sprice) * 1.08; confirm("this total: " + total); } </script>
this html submit button:
<input type="submit" value="submit" onclick="return calculate()" />
put function:
if(confirm("this total: " + total)) { // confirm returns true = ok clicked return true; } else { // confirm returns false = cancel clicked return false; }
Comments
Post a Comment