Jump to content

[SOLVED] Calculate Total Help


radar

Recommended Posts

Okay, ive taken over on a web development project, and I've got little to no knowledge of Javascript.

 

On one page this code works (though it's a little different on this page than on the other)

 

Javascript code:

 
<script language="javascript">
function recalctotal()
{
tot = 0;


tot = tot + document.getElementById("tuesbreakadult").value * 12;
tot = tot + document.getElementById("tuesbreakchild").value * 7;
tot = tot + document.getElementById("tueslunchadult").value * 14.50;
tot = tot + document.getElementById("tueslunchchild").value * 9.50;
tot = tot + document.getElementById("tuesdinneradult").value * 15;
tot = tot + document.getElementById("tuesdinnerchild").value * 13;
tot = tot + document.getElementById("wedsbreakadult").value * 12;
tot = tot + document.getElementById("wedsbreakchild").value * 7;
tot = tot + document.getElementById("wedslunchadult").value * 14.50;
tot = tot + document.getElementById("wedslunchchild").value * 9.50;
tot = tot + document.getElementById("wedsdinneradult").value * 15;
tot = tot + document.getElementById("wedsdinnerchild").value * 13;

tot = tot + document.getElementById("thursbreakadult").value * 12
tot = tot + document.getElementById("thursbreakchild").value * 7
tot = tot + document.getElementById("thurslunchadult").value * 14.50
tot = tot + document.getElementById("thurslunchchild").value * 9.50
tot = tot + document.getElementById("thursdinneradult").value * 15
tot = tot + document.getElementById("thursdinnerchild").value * 13
tot = tot + document.getElementById("fribreakadult").value * 12
tot = tot + document.getElementById("fribreakchild").value * 7
tot = tot + document.getElementById("frilunchadult").value * 14.50
tot = tot + document.getElementById("frilunchchild").value * 9.50
tot = tot + document.getElementById("sabbreakadult").value * 12
tot = tot + document.getElementByID("sabbreakchild").value * 7
tot = tot + document.getElementByID("sablunchadult").value * 15
tot = tot + document.getElementByID("sablunchchild").value * 13
tot = tot + document.getElementByID("sabdinadult").value * 15
tot = tot + document.getElementByID("sabdinchild").value * 13

tot = tot.toFixed(2); 

document.getElementById("total").innerHTML="<strong>Total:</strong> $"+tot;

}
</script>

 

Basic code of the input boxes:

 

<tr>
      <td class="style11"> </td>
      <td class="style11">Dinner</td>
      <td class="style11"><input type="text" size="1" name="satdinneradult" id="satdinneradult" onchange="javascript:recalctotal();"/> @ $15.00 </td>
      <td class="style11"><input type="text" size="1" name="satdinnerchild" id="satdinnerchild" onchange="javascript:recalctotal();"/> @ $13.00 </td>
    </tr>

 

It's not working, and im unsure as to why...  you can check out the error and output here: http://convention.cog7.org/2009reg/onlinereg5.php

 

then the working code is on: http://convention.cog7.org/2009reg/onlinereg4.php

 

The only difference is, on the onlinereg4.php the JS has this in it:

 

document.getElementById("total").innerHTML="<strong>Total:</strong> $"+tot+".00";

 

instead of:

 

tot = tot.toFixed(2);

 

document.getElementById("total").innerHTML="<strong>Total:</strong> $"+tot;

 

Any help is appreciated.

Link to comment
Share on other sites

Okay So I figured this out.  After searching and searching I remembered that I had an old Javascript / VBScript Book that I had never gone through to learn it.

 

I looked at the book, and changed all the tot = tot + lines to match the following:

 

tot = tot + document.formname.inputname.value * price;

 

and it seems to work, i think even better than the previous.  And it doesn't constantly have an error on the page saying an object was expected.  So -- this topic is solved..  Thank you Thomson Learning (the publisher of the book I have)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.