473,396 Members | 1,866 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,396 software developers and data experts.

Updating a field on a different from as a total

The following page is a test for a form that is meant to accept extra
order information for certain products:
http://www.humanedge.biz/tim/testtotals.htm

The extra field at the bottom is meant to show the total quantity for an
order, but due to the way the form is processed I had to put it on a
seperate form that seems to interfere with the function I use to show the
totals.

The function is as follows:
function CalculateTotal(frm) {
var Total_Quantity = 0
for (var i=0; i < frm.elements.length; ++i) {

form_field = frm.elements[i]

form_name = form_field.name

if (form_name.substring(0,8) == "Quantity") {

item_quantity = parseInt(form_field.value)

if (item_quantity >= 0) {
Total_Quantity += item_quantity
}
}
}
document.TotalQuantity.value = Total_Quantity
}

No matter what format I use, it always seems to say that
'document.TotalQuantity.value' is null or not an object (I even tried
passing both forms involved to the function.)

Thanks.

--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 23 '05 #1
7 1336
Tim Chmielewski wrote:
The following page is a test for a form that is meant to accept extra
order information for certain products:
http://www.humanedge.biz/tim/testtotals.htm

The extra field at the bottom is meant to show the total quantity for an
order, but due to the way the form is processed I had to put it on a
seperate form that seems to interfere with the function I use to show the
totals.

The function is as follows:
function CalculateTotal(frm) {
var Total_Quantity = 0
for (var i=0; i < frm.elements.length; ++i) {

form_field = frm.elements[i]

form_name = form_field.name

if (form_name.substring(0,8) == "Quantity") {

item_quantity = parseInt(form_field.value)

if (item_quantity >= 0) {
Total_Quantity += item_quantity
}
}
}
document.TotalQuantity.value = Total_Quantity
}
document.forms["form name here"].Total_Quantity.value=Total_Quantity

But be wary of using variable names that are also names of form controls.
Mick

No matter what format I use, it always seems to say that
'document.TotalQuantity.value' is null or not an object (I even tried
passing both forms involved to the function.)

Thanks.

Jul 23 '05 #2
Mick White <mw******@BOGUSrochester.rr.com> wrote in
news:Hn*******************@twister.nyroc.rr.com:
Tim Chmielewski wrote:
function CalculateTotal(frm) {
var Total_Quantity = 0
for (var i=0; i < frm.elements.length; ++i) {

form_field = frm.elements[i]

form_name = form_field.name

if (form_name.substring(0,8) == "Quantity") {

item_quantity = parseInt(form_field.value)

if (item_quantity >= 0) {
Total_Quantity += item_quantity
}
}
}
document.TotalQuantity.value = Total_Quantity
}

document.forms["form name here"].Total_Quantity.value=Total_Quantity

But be wary of using variable names that are also names of form
controls. Mick

Now it wants ; on every line, even those that don't need one.

Thanks.

--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 23 '05 #3
Tim Chmielewski <ch***@dcsi.net.au> wrote in
news:Xn****************************@130.133.1.4:

document.forms["form name here"].Total_Quantity.value=Total_Quantity

But be wary of using variable names that are also names of form
controls. Mick

Now it wants ; on every line, even those that don't need one.


I found that error, but it is still doing the same thing as before.

Thanks.
--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 23 '05 #4
Tim Chmielewski wrote:
Tim Chmielewski <ch***@dcsi.net.au> wrote in
document.forms["form name here"].Total_Quantity.value=Total_Quantity

But be wary of using variable names that are also names of form
controls. Mick


Now it wants ; on every line, even those that don't need one.

I found that error, but it is still doing the same thing as before.

Thanks.

URL?

Mick
Jul 23 '05 #5
Mick White <mw******@BOGUSrochester.rr.com> wrote in news:ianHc.23700
$b********@twister.nyroc.rr.com:
I found that error, but it is still doing the same thing as before.

Thanks.

URL?

http://www.humanedge.biz/tim/testtotals.htm

Thanks.
--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 23 '05 #6
Tim Chmielewski wrote:
Mick White <mw******@BOGUSrochester.rr.com> wrote in news:ianHc.23700
$b********@twister.nyroc.rr.com:

I found that error, but it is still doing the same thing as before.

Thanks.


URL?


http://www.humanedge.biz/tim/testtotals.htm

Thanks.

You have improperly nested your <form> tags, and your hidden tag is in
no man's land between </td> and <tr>.
Mick
Jul 23 '05 #7
JRS: In article <Xn****************************@130.133.1.4>, seen in
news:comp.lang.javascript, Tim Chmielewski <ch***@dcsi.net.au> posted at
Thu, 8 Jul 2004 22:54:53 :
item_quantity = parseInt(form_field.value)

if (item_quantity >= 0) {
Total_Quantity += item_quantity


Other things apart :

Function parseInt is unsafe without a second parameter, unless the input
is controlled; read the FAQ.

ISTM best to check all such inputs with a RegExp; see my js-valid.htm.

There is no need to avoid adding zero to a number; only if the total
number *and* proportion of zeroes is large does there seem to be any
chance of saving time thereby. If the quantity is negative it should
not be ignored.

Variables introduced in a function should use var, unless they need to
be global (in which case it is probably clearer to define them outside).

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Flavio | last post by:
Hi, I heard time and again that you are not _supposed_ to update the locals dictionary. Can anyone tell me why, if the following code works, I should not do this? # # Extending Local...
1
by: Aravind | last post by:
Hi folks. I have 2 tables, AccList and Book. Book has ISBN as its primary key, while AccList has AccNo as its primary key (data type = Autonumber) and ISBN as its foreign key. The entries...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
11
by: Eych | last post by:
I get a VB error when I try to update a table whose field I change with the following statement: dcUpdate.Dataset.Tables(0).Rows(0)("User Name") = Me.textbox1.Text if I change the field name...
2
by: Chippy | last post by:
I am having trouble working out how to update a field on an open form with a calculation based upon calculations from other tables! For example, I have 3 tables: Diary Diary_ID: autonum,...
1
by: Chippy | last post by:
I am having trouble working out how to update a field on an open form with a calculation based upon calculations from other tables! For example, I have 3 tables: Diary Diary_ID: autonum,...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.