Results 1 to 2 of 2

Thread: I need help please!

  1. #1
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help please!

    I need help please!

    Could someone tell me why I get an error message with this script. It's for a college assignment I'm trying to work on. I'm new to javascript and have only some experience with VB. The script is posted below this message.

    I trying to get a running total cost every time I click "go for it" button. The total cost is determined by multiplying additional (addmarkstxt) by a number that the If statement will figure out.

    I would appreciate your help. Thanks.

    David

    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>

    <script language = "javascript">

    document.emarks.numofcoursestxt.value = "0"
    document.emarks.totalcosttxt.value ="0"

    function calculate()
    {
    var numofcourses = 0;
    var totalcost, addmarks;

    addmarks = parseInt(document.emarks.addmarkstxt.value);


    If (addmarks<=4)
    {totalcost = addmarks*5);
    If (addmarks>=5)
    {totalcost = addmarks*10);
    If (addmarks>=10)
    {totalcost =addmarks*15);

    totalcost+= totalcost;
    numofcourses = numofcourses + 1;

    document.emarks.numofcoursestxt.value = numofcourses;
    document.emarks.totalcosttxt.value = totalcost;
    }

    </script>

    </head>
    <body>


    <form name = "emarks">
    <b>E-Marks:</b>
    <p>
    ID <input name = "idtxt" type = "text" size="5"><br>
    Course Number <input name = "coursenumtxt" type = "text" size="5"><br>
    Description <input name = "descriptiontxt" type = "text" size="10"><br>
    Distance Education <input name = "dised" Checked type = "checkbox" value="off"><br>
    Additional marks <input name = "addmarkstxt" type = "text" size="5"><br><br>
    Number of courses <input name = "numofcoursestxt" type = "text" size="5">
    Total Cost <input name = "totalcosttxt" type = "text" size="5"><br><br>
    <input type = "button" value = "Go for it" onclick= "calculate()"> <input type = "button" value = "Clear and Reset">
    </p>
    </form>



    </body>

    </html>

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    JavaScript IS case sensitive when you use "if" it has to be lower case.
    Also, any document object has to be within a function, if it's outside it won't work. Here it is:

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    
    <script language = "javascript">
    
    
    function calculate()
    { 
    document.emarks.numofcoursestxt.value = "0"
    document.emarks.totalcosttxt.value ="0"
    var numofcourses = 0;
    var totalcost, addmarks;
    
    addmarks = parseInt(document.emarks.addmarkstxt.value);
    
    
    if (addmarks<=4) {totalcost = addmarks*5}; 
    if (addmarks>=5) {totalcost = addmarks*10}
    if (addmarks>=10) {totalcost =addmarks*15}; 
    
    totalcost+= totalcost;
    numofcourses = numofcourses + 1;
    
    document.emarks.numofcoursestxt.value = numofcourses;
    document.emarks.totalcosttxt.value = totalcost;
    }
    
    </script>
    
    </head>
    <body>
    
    
    <form name = "emarks">
    <b>E-Marks:</b>
    <p>
    ID <input name = "idtxt" type = "text" size="5"><br>
    Course Number <input name = "coursenumtxt" type = "text" size="5"><br>
    Description <input name = "descriptiontxt" type = "text" size="10"><br>
    Distance Education <input name = "dised" Checked type = "checkbox" value="off"><br>
    Additional marks <input name = "addmarkstxt" type = "text" size="5"><br><br>
    Number of courses <input name = "numofcoursestxt" type = "text" size="5">
    Total Cost <input name = "totalcosttxt" type = "text" size="5"><br><br>
    <input type = "button" value = "Go for it" onclick= "calculate()"> <input type = "button" value = "Clear and Reset"> 
    </p>
    </form>
    
    </body>
    
    </html>
    - Mike

Bookmarks

Posting Permissions

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