How to Develop Your Own Web Application

Day 2: Calculating hours worked HTML5 form

In this second module, we need to decide the pay period: weekly, semi-monthly or monthly. I chose weekly for this lesson. The pay period is important for determining the hours and payroll deductions.
  1. First we have to retrieve our file containing employees' names, job titles, marital status, exemptions and pay rates.
  2. Next we want to load that data into a table.
  3. Now we have to determine how the user enters the hours worked.
  4. I chose the HTML5 input number field. You can specify a minimum and maximum number of hours to be input.
  5. In our company, employees usually work on average 40 hours per week.
  6. Some work 35 hours and some may put in 5 hours of overtime, hours greater than 40 for a maximum of 45 hours.
  7. We can also set a value of 35 and the user can then scroll up or down to increase or decrease that number.
  8. We first retrieve the file with employee names. This is the same file as on the previous page.
  9. The body onload tag calls the retrieve file function.
  10. Next we want to give the user the opportunity to enter the hours.
  11. Listed below is the html5 code for this.

Copy the code in the textarea box above and save it with an html extension. You might want to call this second module register.html

Adding the javascript function to retrieve the file from local storage.

Here is the code.



Open up your register.html page. Copy the code in the textarea box, paste it between the script tags above and save it.

Day 3: Payroll Register

The payroll register is an accounting form that show us our company's payroll costs. Below is a sample of what one might look like. It is just a table with rows and columns and headings. We will fill it with our employees information soon. We have already added the html code for the payroll register and the employers' payroll taxes.



The Calculate() function.



Paste it just below the retrieve function. Save your register.html file.
The calculate() function function is quite extensive.
  1. First we check to see that the user clicked on one of the week radio buttons.
  2. If they did not pick a week, we do not let them enter hours worked.
  3. next we initialize the variables for each employee.
  4. grossPay, overtimeHours,overtimePayRate and overtime amount.
  5. Next we get the hours worked from the user.
  6. Users will use the up and down arrow keys to enter number of hours over 35.
  7. Now we put those hours into the payroll register table.
  8. Now we calculate overtime for each employee if there is any.
  9. If there is no overtime, we get gross pay by multiplying hourly rate time hours worked.

Now we need to deal with federal income tax that needs to deducted from each employee's paychecks There are two methods for calculating federal income tax: Wage Bracket and Percentage Method. I got the information on line. Use the most current tax tables. I used the wage bracket method. It is a little simplier to code. Both IRS tables are shown below.


Jerry is married and files jointly and his wife does not work outside of the household.

Janet is married and files separately

Julie is single

Shelley is married and files separately

Let's look at Jerry federal Income first. Wage and Bracket table, first column standard withholding
The code for this is for the wage and bracket method is as follows:

else if (grossPay0 >=1210 && grossPay0<1220 ) { fedIncTax0 = 81; document.getElementById("fedIncTax0").innerHTML = fedIncTax0.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); }


Percentage method. Look up 1,213.63 in table. Tax for this amount ,standard withholding, married filing jointly is $38.00 plus 12% of any amount over $857 $1,213.63- $857.00 = $356.63 times 12% equals $42.79 + $38.00 = $80.79 federal tax. As you can see both tables produce essentially the same results. if you were to code this using javaScript, it would look like this.

else if (grossPay0 >=1210 && grossPay0<1220 ) { fedIncTax0 = 38.00 + (grossPay0-857) * .12; document.getElementById("fedIncTax0").innerHTML = fedIncTax0.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); }

Day 4: javaScript code for federal income tax wage and bracket


Copy the code in the textarea box above. Paste this code into your project just below the javaScript code for calculating hours worked.


Day 6: Determining FICA, Medicare, State Disability Insurance and State Training Tax

FICA stands for Federal Insurance Contributions Act, Social Security. It is a 6% deduction from employee paychecks. The employer must also match this amount of tax. A wage base limit applies to employees who pay Social Security taxes. This means that gross income above a certain threshold is exempt from this tax. The wage limit changes almost every year based on inflation. For 2019, it was $132,900. For 2020, it’s $137,700. Wages paid exceeding $137,700 are not subject to the tax. As you can see from our payroll numbers, no employee will exceed this limit, so all of their earnings will be subject to the tax.
We are going to store the percentages for these taxes in local HTML5 storage. Next we will determine the fica deduction for each employee. Then we will take the fica and medicare deductions and load them into the payroll register. Next we store sdi at .005 and state traing at .001, store these numbers, calculate these taxes and load them into the payroll register.


Copy the code in the textarea box above. Paste this code into your project just below the javaScript code for calculating gross pay.