By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

HTML/Javascript Tip Calculator Not Working

P: 3
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
  5. <title>Simple Tip Calculator</title> 
  6. </head> 
  7. <body> 
  8. <form id="tip_calc"> 
  9. <p>Tip Percent: <input id="percent" /></p> 
  10. <p>Amount: <input id="amount" /></p> 
  11. <p><input type="submit" /></p> 
  12. <hr /> 
  13. <p>Tip: <input id="tip" disabled="disabled" /></p> 
  14.  
  15. <p>Total: <input id="total" disabled="disabled" /></p> </form> 
  16. </body> 
  17. <script type="text/javascript">
  18.     function calc () {
  19.  
  20.         var percent = $('#percent').val();
  21.         var amount = $('#amount').val();
  22.         var tip = (percent / 100) * amount;
  23.         var total = Number(amount) + tip;
  24.  
  25.         $('#tip').val( tip.toFixed(2) );
  26.         $('#total').val( total.toFixed(2) );
  27.  
  28.         return false; 
  29.  
  30.     $('#tip_calc').submit(calc);}
  31. </script> 
  32. </html>





Your Help Is Greatly Appreciated
Jan 30 '14 #1
Share this Question
Share on Google+
2 Replies


P: 3
OK I didn't know, sorry about that.
Jan 30 '14 #2

P: 3
Do you know what wrong with my code though? Thanks a bunch.
Jan 30 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.