www.webdeveloper.com
Results 1 to 3 of 3

Thread: whats wrong with this code

  1. #1
    Join Date
    Feb 2003
    Posts
    8

    whats wrong with this code

    hello!

    i have the following assignment to do. below is the question and the code from the two files. when i click on "calculate pay" in first file, it opens a page which is showing the asp code. can you pls tell me whats wrong?

    the question:

    Write a Web application that computes and displays the total pay for an employee. The application should accept regular hours, overtime, and the hourly wage rate for one employee, using an employee timesheet as input. The employee timesheet will be an html form. Be sure to invoke an asp function to calculate the pay.

    Be sure you name the text boxes you created so you can call the information from them.

    Display the output to an asp page called calculate.asp
    In your code you will need to declare variables for regular hours, overtime hours, hourly wage, commission, and total sales.
    You should declare the hours as double and the wage variables as currency.
    "Use the following for calculating commission: Commission = Sales * .06"
    You will need to calculate the total earnings by using the following formula.
    (Regular hours * hourly wage) + (overtime hours *(hourly wage *1.5))
    Display all this to the screen on calculate.asp with the descriptive text as well.


    i am pasting the html code from the 1st one here and am attaching the second file:

    <HTML>

    <HEAD>

    <TITLE> WAGE CALCULATOR </TITLE>

    </HEAD>

    <BODY>

    <FORM NAME = "CALCULATOR" ACTION="calculator.asp" METHOD="POST">

    <SCRIPT LANGUAGE="JavaScript">
    <!--hide from incompatible browsers


    <!--the function below will require that the form fields are validated-->

    function confirmFields() {

    var count = 0;

    var missingFields = 0;

    while (count < document.CALCULATOR.length -1) {

    if (document.pFORM.elements[count].value =="")

    missingFields = ++missingFields;

    ++count;

    }

    <!--the code below will display an alert message to the user, signalling the number of fields left empty-->

    if(missingFields >0) {

    alert("You are missing" + missingFields + "out of" +

    (document.CALCULATOR.length -1) + "fields.");

    return false;

    }

    else

    return true;
    }

    //stop hiding from incompatible browsers-->

    </script>
    <h4> Enter the number of regular hours worked:</h4>

    <INPUT TYPE="TEXT" NAME= "Regular Hours" ><br>

    <h4>Enter the number of overtime hours worked:</h4>

    <INPUT TYPE="TEXT" NAME="Overtime Hours" ><br>

    <h4>Enter Hourly wage: $</h4>

    <INPUT TYPE="TEXT" NAME="Hourly wage" ><br>

    <h4>Enter your total sales:</h4>


    <INPUT TYPE="TEXT" NAME="Total Sales" ><br>

    <p>&nbsp;</P>


    <input type="submit" name="submit" value="Calculate Pay"><br>


    </FORM>

    </BODY>


    </HTML>


    <HTML>

    <HEAD>

    <TITLE> WAGE CALCULATOR </TITLE>

    </HEAD>

    <BODY>


    <%

    Dim dblregHours, overHours, curhourWage, commis, Tsales, Tearnings


    Tearning = (dblregHours * curhourWage) + (overHours *(curhourWage *1.5))


    <p> You have earned $<% = Tearnings%> </p>



    commis = Tsales * .06
    <p>You have earned $<% =commis %> commision </P>





    dblregHours = Request."CALCULATOR" (" Regular Hours")

    overHours = Request."CALCULATOR" (" Overtime Hours")

    curhourWage = Request."CALCULATOR" ("Hourly wage")

    Tsales = Request."CALCULATOR" ("Total Sales")


    %>

    </body>
    </html>


    pls help,
    thanks,
    syma.

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,

    there were a few things wrong with your code, so i posted working code for you to see the changes i made. Your main problems was missing opening and closing <% %> asp tags around your asp code. You also tried to request data from .calculator when you should have .form .caluclator is not any asp syntax. I also added some extra code to help the page work better. Here is the code:

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <HTML> 
    
    <HEAD> 
    
    <TITLE> WAGE CALCULATOR </TITLE> 
    
    </HEAD> 
    
    <BODY> 
    
    <FORM NAME = "CALCULATOR" ACTION="calculator.asp" METHOD="POST"> 
    
    <SCRIPT LANGUAGE="JavaScript"> 
    <!--hide from incompatible browsers 
    
    
    <!--the function below will require that the form fields are validated--> 
    
    function confirmFields() { 
    
    var count = 0; 
    
    var missingFields = 0; 
    
    while (count < document.CALCULATOR.length -1) { 
    
    if (document.pFORM.elements[count].value =="") 
    
    missingFields = ++missingFields; 
    
    ++count; 
    
    } 
    
    <!--the code below will display an alert message to the user, signalling the number of fields left empty--> 
    
    if(missingFields >0) { 
    
    alert("You are missing" + missingFields + "out of" + 
    
    (document.CALCULATOR.length -1) + "fields."); 
    
    return false; 
    
    } 
    
    else 
    
    return true; 
    } 
    
    //stop hiding from incompatible browsers--> 
    
    </script> 
    <h4> Enter the number of regular hours worked:</h4> 
    
    <INPUT TYPE="TEXT" NAME= "RegularHours" ><br> 
    
    <h4>Enter the number of overtime hours worked:</h4> 
    
    <INPUT TYPE="TEXT" NAME="OvertimeHours" ><br> 
    
    <h4>Enter Hourly wage: $</h4> 
    
    <INPUT TYPE="TEXT" NAME="Hourlywage" ><br> 
    
    <h4>Enter your total sales:</h4> 
    
    
    <INPUT TYPE="TEXT" NAME="TotalSales" ><br> 
    
    <p> </P> 
    
    
    <input type="submit" name="submit" value="CalculatePay">
      <input name="cal" type="hidden" id="cal" value="yes">
      <br> 
    
    
    </FORM> 
    
    </BODY> 
    <%
    Dim dblregHours, overHours, curhourWage, commis, Tsales, Tearnings, cal 
    dblregHours = Request.form("RegularHours") 
    overHours = Request.form("OvertimeHours") 
    curhourWage = Request.form("Hourlywage") 
    Tsales = Request.form("TotalSales") 
    cal = request.form("cal")
    if cal = "yes" then
    
    Tearning = (dblregHours * curhourWage) + (overHours *(curhourWage *1.5)) 
    %>
    
    <p> You have earned $<%=Tearning%> </p> 
    
    <%
    commis = Tsales * .06 
    %>
    <p>You have earned $<%=commis%> commision </P> 
    <%end if%>
    </body> 
    </html>
    ----------------------------------

  3. #3
    Join Date
    Feb 2003
    Posts
    8
    hello,
    thanks a lot for your help. i made the changes to the code. there were a couple of things i needed to ask though, what does "CODEPAGE="1252" mean. also for some reason, inspite of having iis installed, i cannot view asp code on my machine so when i hit, calculate pay, i was getting:

    You have earned $

    You have earned $ commision
    and not any nos. can you see the nos?

    can you pls review my code to see if all is right. also the field validation is not working, that is a requirement of this assignment, i need to validate all my fields.
    below is the code from my two files:

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <HTML>

    <HEAD>

    <TITLE> WAGE CALCULATOR </TITLE>

    </HEAD>

    <BODY>

    <FORM NAME = "CALCULATOR" ACTION="calculator.asp" METHOD="POST">

    <SCRIPT LANGUAGE="JavaScript">
    <!--hide from incompatible browsers


    <!--the function below will require that the form fields are validated-->

    function confirmFields() {

    var count = 0;

    var missingFields = 0;

    while (count < document.CALCULATOR.length -1) {

    if (document.pFORM.elements[count].value =="")

    missingFields = ++missingFields;

    ++count;

    }

    <!--the code below will display an alert message to the user, signalling the number of fields left empty-->

    if(missingFields >0) {

    alert("You are missing" + missingFields + "out of" +

    (document.CALCULATOR.length -1) + "fields.");

    return false;

    }

    else

    return true;
    }

    //stop hiding from incompatible browsers-->

    </script>
    <h4> Enter the number of regular hours worked:</h4>

    <INPUT TYPE="TEXT" NAME= "RegularHours" ><br>

    <h4>Enter the number of overtime hours worked:</h4>

    <INPUT TYPE="TEXT" NAME="OvertimeHours" ><br>

    <h4>Enter Hourly wage: $</h4>

    <INPUT TYPE="TEXT" NAME="Hourlywage" ><br>

    <h4>Enter your total sales:</h4>


    <INPUT TYPE="TEXT" NAME="TotalSales" ><br>

    <p> </P>


    <input type="submit" name="submit" value="CalculatePay">
    <input name="cal" type="hidden" id="cal" value="yes">
    <br>


    </FORM>

    </BODY>
    </html>

    following is the code form the file to which i want to post the data:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <HTML>

    <HEAD>

    <TITLE> CALCULATOR </TITLE>

    </HEAD>

    <body>

    <%
    Dim dblregHours, overHours, curhourWage, commis, Tsales, Tearnings, cal
    dblregHours = Request.form("RegularHours")
    overHours = Request.form("OvertimeHours")
    curhourWage = Request.form("Hourlywage")
    Tsales = Request.form("TotalSales")
    cal = request.form("cal")
    if cal = "yes" then

    Tearning = (dblregHours * curhourWage) + (overHours *(curhourWage *1.5))
    %>

    <p> You have earned $<%=Tearning%> </p>

    <%
    commis = Tsales * .06
    %>
    <p>You have earned $<%=commis%> commision </P>
    <%end if%>

    </body>
    </html>

    thanks,
    syma.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles