Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>CIS 223 Lab Assignment #4</title>
- </head>
- <body>
- <h2>This is the lab assignment #4</h2>
- <form>
- <table>
- <h4>
- <tr>
- <td>Name</td><td><input type="text" id="name" size=20 /></td></tr>
- <tr>
- <td>Hours Worked</td><td><input type="text" id="hours" size=8 /></td></tr>
- <tr>
- <td>Pay Rate</td><td><input type="text" id="rate" size=8 /></td></tr>
- <tr>
- <td>Gross Pay</td><td><input type="text" id="grossPay" size=8 DISABLED /></td></tr>
- <tr>
- <td>Tax</td><td><input type="text" id="tax" size=8 DISABLED /></td></tr>
- <tr>
- <td>Net Pay</td><td><input type="text" id="netPay" size=8 DISABLED /></td></tr>
- </table>
- <p><input type="button" value="Calculate" id="calculate" /></p>
- </form>
- <script>
- var hours = 0;
- var rate = 0.0;
- var grossPay = 0.0;
- var tax = 0.0;
- var netPay = 0.0;
- function process() {
- grossPay = hours * rate;
- document.getElementById("grossPay").value = grossPay;
- tax = grossPay * 0.10;
- document.getElementById("tax").value = tax;
- netPay = grossPay - tax;
- document.getElementById("netPay").value = netPay;
- }
- function verifyValues()
- {
- hours = document.getElementById("hours").value;
- rate = document.getElementById("rate").value;
- try {
- if(hours === "")
- throw "Hours or Rate should not be blank"
- if(rate === "")
- throw "Hours or Rate should not be blank"
- if (hours < 0)
- throw "Please enter positive value for hours";
- if (rate < 8.25)
- throw "Minimum wage is $8.25 per hour";
- }
- catch(error) {
- window.alert(error)
- return false;
- }
- process();
- }
- // add backward compatible event listener to Submit button
- var submitButton = document.getElementById("calculate");
- if (submitButton.addEventListener) {
- submitButton.addEventListener("click", verifyValues, false);
- }
- else if (submitButton.attachEvent) {
- submitButton.attachEvent("onclick", verifyValues);
- }
- </script>
- </h4>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement