javascript - JQuery - How to implement Cancel Button -
<html> <body> <form class="totalpayment"> <input class="paid" type="text" name="numberone" /> <input class="due" type="text" name="numbertwo" /> <button>add</button> </form> <p class="total"></p> <script src="jquery.min.js"></script> <script> // sum value when submitting form $(".totalpayment").submit(function(e){ e.preventdefault(); var paid = parseint($('.paid').val()); var due = parseint($('.due').val()); $(".total").html(paid + due); }); </script> </body> </html>
i have form adds 2 numbers together. issue is, has 1 button, add button. let's wanted add handler cancel button clear 2 boxes, how implement this?
just add 1 more button reset form. read more reset button
there no need add handler resetting form.
<button type="reset" value="cancel">cancel</button>
sample code:
<html> <body> <form class="totalpayment"> <input class="paid" type="text" name="numberone" /> <input class="due" type="text" name="numbertwo" /> <button>add</button> <button type="reset" value="cancel">cancel</button> </form> <p class="total"></p> <script src="jquery.min.js"></script> <script> // sum value when submitting form $(".totalpayment").submit(function(e){ e.preventdefault(); var paid = parseint($('.paid').val()); var due = parseint($('.due').val()); $(".total").html(paid + due); }); </script> </body> </html>
Comments
Post a Comment