473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5033
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.