#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Calculate the weekly or monthly regular or overtime pay for employees


    Hey guys, I am seeing your help on finding out what I am doing wrong with this code to print out the result in a form. See my code below

    HTML4Strict Code:
    <html>
    <head>
     
     
    <script type="text/javascript"> 
    <!--		              
        function calculate() {
    	var weekly_regular_rate = 17.5;
    	var weekly_Overtime_rate = 32.5;
    	var monthly_regular_rate = 52.00;
    	var monthly_overtime_rate = 98.75;
    	var income_tax = 0.15;
    	var overtime = 40;               
    	var pay = 0;                         
    	var total = 0;  
    	var grosspay = 0;	
     
    	if (hours_worked <=0){
    		alert("Please enter a valid number, Thank you.")/*displays error message*/
    		}
    		else	{
    			if (form.weekly.value == "checked" && hoursworked > overtime) 
    			pay = (hoursworked * weekly_regular_rate) + weekly_overtime_rate * (hoursworked - overtime)/* * wage;*/
    			}
    		else
    			{
    			if (form.weekly.value == "checked" && hoursworked <= overtime) 
    			pay = weekly_regular_rate * hoursworked;
    			}
    		else{
    			if (form.monthly..value == "checked" && hoursworked > overtime) 
    			pay = (hoursworked * monthly_regular_rate) + monthly_overtime_rate * (hoursworked - overtime)/* * wage;*/
    			}
    		else
    			{
    			if (form.monthly.value == "checked" && hoursworked <= overtime) 
    			pay = monthly_regular_rate * hoursworked;
    			}
    		grosspay = income_tax/100 * pay;
     
    		document.payrollsystem.grosspay.value = total;
    //-->		
    }
    </script>
    </head>
    <body>
        <form name="payrollsystem">
           Employee Name: <input type ="text" id="name"/><br><br>
    	   Hours Worked: <input type ="number" size = "3" id="hoursworked" /><br> <br>
    	   Select Employee's Category: <br>
     
    	   Weekly<input type ="checkbox" id="weekly" /><br>
    	   Monthly<input type ="checkbox" id="monthly" /><br>     <br>
           <input type="button" value="calculate" onclick="calculate()" />
           <input type="reset" value="Clear" /><br /><br>
    	   Gross Pay <input type = "number" name = "total" /> 
    	   Employee Name <input type = "text" name = "name" />
     
     
        </form>
    </body>
    </html>
    Last edited by Winters; November 14th, 2013 at 01:15 PM. Reason: Added highlighting.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,129
    Rep Power
    119
    There is a lot of variables, in your code, that you do not have defined, like: hours_worked, form, and monthly (you are referencing it as a name attribute, not an id attribute... like you have it in your input field). You also have two periods, in the code segment below and you only need one
    Code:
    form.monthly..value
    . Basically you have quit a few errors, that your going to need to fix, before your code is going to be able to work. Did someone else give you this code or did you get it off of a website or something; it is not a good example, if you did? My suggestion would be, for you to do some online research about "JavaScript Form Validation". That way you will have a good understanding of the correct way to validate a HTML form via JavaScript.

IMN logo majestic logo threadwatch logo seochat tools logo