473,503 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

for loop

Hi,

I need help to make this a loop.

dsum1 = document.form1.c1.value;
dsum1 -=0;
dsum2 = document.form1.c2.value;
dsum2 -=0;
dsum3 = document.form1.c3.value;
dsum3 -=0;
dsum4 = document.form1.c4.value;
dsum4 -=0;
dsum5 = document.form1.c5.value;
dsum5 -=0;
dsum6 = document.form1.c6.value;
dsum6 -=0;

saldo = dsum1 + dsum2 + dsum3 + dsum4 + dsum5 + dsum6;

Thanks in advance.
Jan Grafström
Jul 20 '05 #1
5 1989
"Christina Grafström" <ch**********@telia.com> writes:
I need help to make this a loop.

dsum1 = document.form1.c1.value;
dsum1 -=0; .... dsum6 = document.form1.c6.value;
dsum6 -=0;

saldo = dsum1 + dsum2 + dsum3 + dsum4 + dsum5 + dsum6;


I assume you don't want the six global variables dsum1 ... dsum6 if you
can avoid them.

var form = document.forms['form1'];
var saldo = 0;
for (var i=1 ; i<=6 ; i++) {
saldo += +(form.elements["c"+i].value);
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse Reichstein Nielsen wrote:
"Christina Grafström" <ch**********@telia.com> writes:

I need help to make this a loop.

dsum1 = document.form1.c1.value;
dsum1 -=0;
...
dsum6 = document.form1.c6.value;
dsum6 -=0;

saldo = dsum1 + dsum2 + dsum3 + dsum4 + dsum5 + dsum6;

I assume you don't want the six global variables dsum1 ... dsum6 if you
can avoid them.

var form = document.forms['form1'];
var saldo = 0;
for (var i=1 ; i<=6 ; i++) {
saldo += +(form.elements["c"+i].value);
}

Very interesting notation. I get the += and the (form.....) bit as well
but why the + in front of the (form...)?

TIA
Fermin DCG
btw. thx for the inheritance tip
/L


Jul 20 '05 #3
Da Costa Gomez <dc*@xs4all.nl> writes:
why the + in front of the (form...)?


The prefix plus sign is the shortest and fastest way of turning a
string into a number. It is equivalent in function to parseFloat.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
JRS: In article <vf**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Mon, 8 Sep 2003 18:35:47 :-
Da Costa Gomez <dc*@xs4all.nl> writes:
why the + in front of the (form...)?


The prefix plus sign is the shortest and fastest way of turning a
string into a number. It is equivalent in function to parseFloat.


Provided that the string contains only the number and optional
surrounding whitespace.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 20 '05 #5
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
Provided that the string contains only the number and optional
surrounding whitespace.


That is correct. The functions parseInt and parseFloat allows garbage
after the number, so parseInt("127XPgLop",10)==127. Probably so that
one can use it in a parser (but it doesn't tell how many charcters
it reads, so it is useless in making a parser).

It would be more precise to say that prefix plus is equivalent to the
function "Number".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

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

Similar topics

0
2911
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
5244
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
5527
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
7283
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
4594
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
2658
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
3504
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
2554
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
3490
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
19288
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
7205
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
7353
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...
1
7011
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
7468
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
5596
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
5023
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
4689
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
1521
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 ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.