Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2009, 03:35 PM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 5
Thanked 2 Times in 2 Posts
Default Rookie question

I'm new to programming and I have the task of revising an existing piece of code. I have revised part of it and I need help with the rest. I need to know how to get a total and make it a "running" total, where whenever someone adds an amount it gives the running total. This is the section of code I have now. It has been a while since I had any classes and I'm REAL rusty. I also need to know, do I need to declare all of these amounts as variables? And what about the total itself?? Like I said, I'm new at this. Thanks in advance!! BTW, I'm using Notepad++.

<TR>
<TD class="body"> <label class="labels" for="gift_num1">Library Excellence Activities</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT1" id="GIFT_AMOUNT1" SIZE="8" value="0.00" ;" /></TD>

</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num2">Education & Psychology Collection Endowment</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT2" id="GIFT_AMOUNT2" SIZE="8" value="0.00" ;" /></TD>
</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num3">Humanities Collection Endowment</Label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT3" id="GIFT_AMOUNT3" SIZE="8" value="0.00" ;" /></TD>
</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num4">Science Collection Endowment</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT4" id="GIFT_AMOUNT4" SIZE="8" value="0.00" ;" /></TD>
</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num5">Social Studies Collection Endowment</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT5" id="GIFT_AMOUNT5" SIZE="8" value="0.00" ;" /></TD>
</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num6">Special Collections Endowment</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT6" id="GIFT_AMOUNT6" SIZE="8" value="0.00" ;" /></TD>
</TR>
<TR>
<TD class="body"><label class="labels" for="gift_num7">Other</label></TD>
<TD>$ <INPUT TYPE="TEXT" NAME="GIFT_AMOUNT7" id="GIFT_AMOUNT7" SIZE="8" value="0.00" ;" /></TD>
</TR>

<TR>

<TD><strong>total</strong></TD>

<TD>$
<INPUT TYPE="TEXT" NAME="total" id="total" SIZE="8" value="0.00" ;" /></TD>


</TR>
 
Old December 11th, 2009, 03:47 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can't achieve this using HTML alone. You are going to need to use, at least, some JavaScript. Do you have any knowledge of JavaScript?
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
mitch54 (December 11th, 2009)
 
Old December 11th, 2009, 04:13 PM
Authorized User
 
Join Date: Oct 2009
Posts: 14
Thanks: 5
Thanked 2 Times in 2 Posts
Default

Not much....I do have some javascript code in the page. It gives a total, but it is on the second page. I have a page that, when you click on the button, it takes you to another page. I can get the total on the second page, but not on the first one. Here is the javascript for that part.
}

var num, i, j;
var comm = "";
var comm1 = "";
var comm2 = "";
var comm3 = "";
function Calculate()
{
var total=0;
// calculate each line total

if (document.getElementById('gift_num1').value >= 0){
document.getElementById('GIFT_AMOUNT1').value= (document.getElementById('gift_num1').value ).toFixed(2);
}

if (document.getElementById('gift_num2').value >= 0){
document.getElementById('GIFT_AMOUNT2').value = (document.getElementById('gift_num2').value ).toFixed(2);
}

if (document.getElementById('gift_num3').value >= 0) {
document.getElementById('GIFT_AMOUNT3').value = (document.getElementById('gift_num3').value ).toFixed(2);
}
if (document.getElementById('gift_num4').value >= 0){
document.getElementById('GIFT_AMOUNT4').value = (document.getElementById('gift_num4').value ).toFixed(2);

}
if (document.getElementById('gift_num5').value >= 0){
document.getElementById('GIFT_AMOUNT5').value = (document.getElementById('gift_num5').value ).toFixed(2);

}
if (document.getElementById('gift_num6').value >= 0){
document.getElementById('GIFT_AMOUNT6').value = (document.getElementById('gift_num6').value ).toFixed(2);

}
if (document.getElelmentById('gift_num7').value>=0){
document.GetElementById('GIFT_AMOUNT7').value=(doc ument.getElementById('gift_num7').value).toFixed(2 );



total = parseFloat(document.getElementById('GIFT_AMOUNT1') .value)+ parseFloat(document.getElementById('GIFT_AMOUNT2') .value) + parseFloat(document.getElementById('GIFT_AMOUNT3') .value) + parseFloat(document.getElementById('GIFT_AMOUNT4') .value) + parseFloat(document.getElementById('GIFT_AMOUNT5') .value) + parseFloat(document.getElementById('GIFT_AMOUNT6') .value) + parseFloat(document.getElementById('GIFT_AMOUNT7') .value);
var num= Math.round(total * 100) / 100
document.getElementById('total').value = num.toFixed(2);
}

}
does this help? Like I said, it's been a couple of three years since I had any programming classes.
 
Old April 7th, 2010, 01:18 PM
Registered User
 
Join Date: Apr 2010
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
Default

You will definitely need some Javascript, but I can't help you out with that, since I'm not so familiar with Javascript...yet
But you should be aware that in XHTML, you're not supposed to capitalize elements/tags.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help PHP Rookie Stuck Chapter 1! shinigami BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 3 November 14th, 2009 12:45 AM
Disappearing UserName & Question within Customized PasswordRecovery Question Template eddiemcham ASP.NET 3.5 Basics 13 June 13th, 2009 04:23 AM
Small rookie question maximus101 VB Databases Basics 1 February 23rd, 2006 11:51 PM
Rookie question: container div not containing CFGerry BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 6 September 1st, 2005 09:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.