472,950 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

autosum textbox for grand total on form

Hi,

I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it doesn't seem to be working. Here is my code. Thanks for your help.
-sammie

[HTML]<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Nursing Conference 2007 Registration Form</title>



<script language="javascript" type="text/javascript">
// Calculate the total for items in the form which are selected.
function calculateTotal(inputItem) {
with (inputItem.form) {
// Process each of the different input types in the form.
if (inputItem.type == "radio") { // Process radio buttons.
// Subtract the previously selected radio button value from the total.
calculatedTotal.value = eval(calculatedTotal.value) - eval(previouslySelectedRadioButton.value);
// Save the current radio selection value.
previouslySelectedRadioButton.value = eval(inputItem.value);
// Add the current radio button selection value to the total.
calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
} else { // Process check boxes.
if (inputItem.checked == false) { // Item was uncheck. Subtract item value from total.
calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
} else { // Item was checked. Add the item value to the total.
calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
}
}

// Total value should never be less than 0.
if (calculatedTotal.value < 0) {
InitForm();
}

// Return total value.
return(formatCurrency(calculatedTotal.value));
}
}

// Format a value as currency.
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

// This function initialzes all the form elements to default values.
function InitForm() {
// Reset values on form.
document.selectionForm.total.value='$0';
document.selectionForm.calculatedTotal.value=0;
document.selectionForm.previouslySelectedRadioButt on.value=0;

// Set all checkboxes and radio buttons on form to unchecked.
for (i=0; i < document.selectionForm.elements.length; i++) {
if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
document.selectionForm.elements[i].checked = false;
}
}
}
</script>




</head>

<body>

<form method="POST" action="--WEBBOT-SELF--" name="conf07reg">
<!--webbot bot="SaveResults" U-File="../_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" i-checksum="43374" endspan -->
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td>
<p align="center"><b><font face="Verdana" color="#333333">CONFERENCE</font></b></p></td>
</tr>
</table>
<table border="0" width="840" cellspacing="0" cellpadding="0" id="table2">
<tr>
<td width="840" colspan="8"><b>
<span style="font-size: 10.0pt; font-family: Verdana; color: #000066">
FEES AND DEADLINES </span><font size="2" color="#333333" face="Verdana"><br>
&nbsp;</font></b></td>
</tr>
<tr>
<td width="192">&nbsp;</td>
<td width="155" colspan="2">
<p align="center"><b><font face="Verdana" size="2" color="#333333">Early
Registration</font></b></td>
<td width="176" colspan="2">
<p align="center"><b><font face="Verdana" size="2" color="#333333">After
10/2007</font></b></td>
<td width="179" colspan="2">
<p align="center"><b><font face="Verdana" size="2" color="#333333">Staff/Student*</font></b></td>
<td width="138">
<p align="center"><b><font face="Verdana" size="2" color="#333333">Total</font></b></td>
</tr>
<tr>
<td width="192"><b><font face="Verdana" size="2" color="#333333">Main Conference (2
days)</font></b></td>
<td width="78">
<p align="right">




<input type="checkbox" name="early2day" value="298.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="78">
<p align="center"><font face="Verdana" size="2" color="#333333">$298.00</font></td>
<td width="88">
<p align="right">
<input type="checkbox" name="aug2day" value="350.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="88">
<p align="center"><font face="Verdana" size="2" color="#333333">$350.00</font></td>
<td width="90">
<p align="right">
<input type="checkbox" name="student2day" value="175.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="90">
<p align="center"><font face="Verdana" size="2" color="#333333">$175.00</font></td>
<td width="138">
&nbsp;</tr>
<tr>
<td width="192"><b><font face="Verdana" size="2" color="#333333">Main Conference (1
day)</font></b></td>
<td width="78">
<p align="right">
<input type="checkbox" name="early1day" value="170.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="78">
<p align="center"><font face="Verdana" size="2" color="#333333">$170.00</font></td>
<td width="88">
<p align="right">
<input type="checkbox" name="aug1day" value="200.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="88">
<p align="center"><font face="Verdana" size="2" color="#333333">$200.00</font></td>
<td width="90">
<p align="right">
<input type="checkbox" name="student1day" value="100.00" onclick="this.form.total.value=calculateTotal(this );"></td>
<td width="90">
<p align="center"><font face="Verdana" size="2" color="#333333">$100.00</font></td>
<td width="138">&nbsp;</td>
</tr>
<tr>
<td width="702" colspan="7">
<font face="Verdana" size="2" color="#333333"> <input type="radio" name="discount" value="20.00" onclick="this.form.total.value=calculateTotal(this );">
<b>Discount</b> -
$20 per
registrant<br>
&nbsp;</font></td>
<td width="138" valign="top">
<input type="hidden" name="calculatedTotal" value="0">
<input type="hidden" name="previouslySelectedRadioButton" value="0">

<p align="right">

<input type="text" name="total" border="0px" readonly onfocus="this.blur();" size="15" style="text-align: right; font-family: Verdana; font-size: 12px; font-weight: bold"></td>
</tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table4">
<tr>
<td valign="top" colspan="4"><b>
<span style="font-size: 10.0pt; font-family: Verdana; color: #000066">
EVENTS</span><font face="Verdana" size="2" color="#333333"><br>
&nbsp;</font></b></td>
</tr>
<tr>
<td valign="top" width="55%">
<font face="Verdana" size="2" color="#333333">Reception </font></td>
<td valign="top" colspan="3">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="55%">
<font face="Verdana" size="2" color="#333333">Party</font></td>
<td valign="top" colspan="3">&nbsp;</td>
</tr>
<tr>
<td valign="top" width="55%">
<font face="Verdana" size="2" color="#333333">Excursion </font></td>
<td valign="top" width="10%">
<font face="Verdana" size="2" color="#333333">
$20/each</font></td>
<td valign="top" width="17%"><font face="Verdana" size="2" color="#333333"># of
tickets
<input type="text" name="casinotix" size="5" style="text-align: center" onblur="this.form.casinototal.value = formatCurrency(this.form.casinotix.value*20)"></font></td>
<td valign="top" width="18%"><font face="Verdana" size="2" color="#333333">$<input type="text" name="casinototal" size="10" border="0px" readonly value="0" style="text-align: right"></font></td>
</tr>
<tr>
<td valign="top" width="55%">&nbsp;</td>
<td align="right" valign="top">
&nbsp;</td>
<td align="right" valign="top">
<font face="Verdana" size="2" color="#333333">TOTAL:</font></td>
<td align="right" valign="top">
<input type="text" name="grandtotal" readonly ></td>
</tr>
</table>
<p><font face="Verdana"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></font></p>
</form>

</body>

</html>[/HTML]
Jul 17 '07 #1
2 4999
pbmods
5,821 Expert 4TB
Heya, sammiesue. Welcome to TSDN!

You lost me. Where is the text box?
Jul 18 '07 #2
sorry about that -- I mashed code from different sources then tweaked it to get the rest of the form working, so it's not the cleanest code written. Here's the textbox setup:

"Total" - line 163 - this textbox gets its sum from the checkboxes and radio button created in lines 115-161.

"casinototal" - line 192. this textbox gets its sum from the onblur event of the "casinotix" textbox on 191.

"grandtotal" - line 201. this is the textbox that I want to autosum from the amounts in "total" and "casinototal"

I hope that's some help.
Jul 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: giancarlodirisioster | last post by:
Can someone help me modify this for future Usenet archival and to help me solve what I don't know? <form name="addform" method="POST" action="./submit.php"> <input type="text" name="Box 1"...
3
by: CSDunn | last post by:
Hello, I have 14 fields on a report that hold integer values. The field names use the following naming convention: T1Number, T2Number ....T14Number. I need to get a 'sub total' of all fields as...
4
by: lyndsey | last post by:
i have a database to keep record of jobs in production, and on one of my forms, their is the control . in my form i have hundereds of records (jobs). is there a way i can create something in my...
6
by: Coleen | last post by:
Hi All :-) Thanks for all of your help Cor :-) I can not get the code you sent me to work in my application. I'm using an aspx datagrid in a web form. I'm getting the following error message...
17
by: barkarlo | last post by:
I need help to make grand total time in continuous forms. to calculate total work time I use following formula =format(+1--nz();"short time"). but when I make grand total time in form footer (for...
1
by: hdogg | last post by:
So, this autosum works perfect but... since i'm dyamically going to submit multiple records... all of the form names will be the same ..." forecast" but when i try to sum all the fields that the...
0
by: jessicaeatworld | last post by:
Hi, I'm using Access 2003 on Windows XP. I have created a PivotTable View Form and at the bottom is an automatically inserted Grand Total row. I added sum and avg fields and then hid the details so...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
3
by: davncong | last post by:
I've created a webform for a user to order from a catalog. There are five colums (item #, quantity, description, price and total) and 10 rows (repeating first row so the user can order up to 10...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.