473,473 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loop and sum

I have an unknown number of textboxes which I want to sum. They are
named something like this:

"ctl00$ContentPlaceHolder1$DataList1$ctl03$DataLis t2$ctl03$txtSumB"

The only thing i know for sure is that "txtSumB" is somewhere in the
name. The page can contain anything from 1 to 50 textboxes.

Can someone please help me with a script which loops through all the
textboxes with "txtSumB" in the name and sums the values?

Very grateful for help!

Regards,

S

Apr 18 '06 #1
2 5156
st****@gmail.com wrote:
I have an unknown number of textboxes which I want to sum. They are
named something like this:

"ctl00$ContentPlaceHolder1$DataList1$ctl03$DataLis t2$ctl03$txtSumB"

The only thing i know for sure is that "txtSumB" is somewhere in the
name. The page can contain anything from 1 to 50 textboxes.

Can someone please help me with a script which loops through all the
textboxes with "txtSumB" in the name and sums the values?


Get the elements within the form, find those with a name that has the
string in it and add them up.

<script type="text/javascript">

function showTotal(form, totalEl)
{
var el, els = form.elements;
var sum = 0;

for (var i=0, num=els.length; i<num; ++i){
el = els[i];

if ('text' == el.type && /SumB/.test(el.name)){
sum += +el.value;
}
form.elements[totalEl].value = sum;
}
}
</script>

<form action=""><div>
<input type="text" name="ZugZug">ZugZug<br>
<input type="text" name="fooSumBxx">fooSumBxx<br>
<input type="text" name="barSumByy">barSumByy<br>
<input type="text" name="sueSumBzz">sueSumBzz<br>
<input type="text" name="formTotal" readonly>Total
<input type="button" value="Show total"
onclick="showTotal(this.form, 'formTotal');">
</div></form>
Note that you need to test the value of each input to see if it's a
number and suitable to be added before actually adding it.
--
Rob
Apr 18 '06 #2
Thank's a lot!

Apr 18 '06 #3

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

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
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,...
1
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.