Advertisement
conception

lab4

Sep 28th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>CIS 223 Lab Assignment #4</title>
  5.  
  6. </head>
  7.  
  8. <body>
  9. <h2>This is the lab assignment #4</h2>
  10. <form>
  11. <table>
  12. <h4>
  13. <tr>
  14. <td>Name</td><td><input type="text" id="name" size=20 /></td></tr>
  15. <tr>
  16. <td>Hours Worked</td><td><input type="text" id="hours" size=8 /></td></tr>
  17. <tr>
  18. <td>Pay Rate</td><td><input type="text" id="rate" size=8 /></td></tr>
  19. <tr>
  20. <td>Gross Pay</td><td><input type="text" id="grossPay" size=8 DISABLED /></td></tr>
  21. <tr>
  22. <td>Tax</td><td><input type="text" id="tax" size=8 DISABLED /></td></tr>
  23. <tr>
  24. <td>Net Pay</td><td><input type="text" id="netPay" size=8 DISABLED /></td></tr>
  25. </table>
  26. <p><input type="button" value="Calculate" id="calculate" /></p>
  27. </form>
  28. <script>
  29. var hours = 0;
  30. var rate = 0.0;
  31. var grossPay = 0.0;
  32. var tax = 0.0;
  33. var netPay = 0.0;
  34.  
  35.  
  36. function process() {
  37. grossPay = hours * rate;
  38. document.getElementById("grossPay").value = grossPay;
  39.  
  40. tax = grossPay * 0.10;
  41. document.getElementById("tax").value = tax;
  42.  
  43. netPay = grossPay - tax;
  44. document.getElementById("netPay").value = netPay;
  45.  
  46. }
  47.  
  48.  
  49. function verifyValues()
  50. {
  51. hours = document.getElementById("hours").value;
  52. rate = document.getElementById("rate").value;
  53.  
  54. try {
  55. if(hours === "")
  56. throw "Hours or Rate should not be blank"
  57.  
  58. if(rate === "")
  59. throw "Hours or Rate should not be blank"
  60.  
  61. if (hours < 0)
  62. throw "Please enter positive value for hours";
  63.  
  64. if (rate < 8.25)
  65. throw "Minimum wage is $8.25 per hour";
  66.  
  67. }
  68. catch(error) {
  69. window.alert(error)
  70. return false;
  71. }
  72.  
  73. process();
  74.  
  75. }
  76.  
  77. // add backward compatible event listener to Submit button
  78. var submitButton = document.getElementById("calculate");
  79. if (submitButton.addEventListener) {
  80. submitButton.addEventListener("click", verifyValues, false);
  81. }
  82. else if (submitButton.attachEvent) {
  83. submitButton.attachEvent("onclick", verifyValues);
  84. }
  85.  
  86.  
  87. </script>
  88. </h4>
  89. </body>
  90. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement