SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Aug 4, 2003, 14:31 #1
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Multiple variables in for statement
Hi there,
I've written some code to calculate a price based on some options choosed by the client.
Now I would like to multiply this code by using a for statement and I am wondering if there is a way to have different variables for each run.
What I mean:
I have e.g.
for (i=1; i <= 3; i++) {
...
ammount1 = 0;
...
}
If i=1 the variable should be ammount1, if i=2 it should be ammount2 and so on. Is there a way to do this? ammount+i = 0 obviously doesn't work
Thanks and regards,
ASchweti
-
Aug 4, 2003, 14:47 #2
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could use an array
Code:var amounts = new Array(); for ( var i = 0; i < 3; i++ ) { amounts[i] = 0; }
-
Aug 4, 2003, 14:56 #3
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am trying to solve this at this very moment, so I was playing around with arrays when I received your reply.
So to me it sounds like the logical solution, but I am getting a "amount is not defined"
Any idea why?
-
Aug 4, 2003, 15:02 #4
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I believe I found it?
My smart O'Reilly book told me to add
Code:amount = new Object();
Thanks ASchweti
-
Aug 4, 2003, 15:07 #5
-
Aug 4, 2003, 15:17 #6
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Beetle,
just read my second post right after yours, that I solved this issue. I just was not sure if I solved it the correct way?!
Anyhow I am facing another problem!
In order to calculate different amounts based on user entries I am using PHP to create the appropriate amount of forms.
The form fields are named e.g. color1 on the first form, color2 on the second form. In order to calculate the price I would need to get a hold of the values.
So again if i=1 I need to check
Code:document.form.color1.checked
Code:document.form.color2.checked
Do you know what I mean? Is there a way to keep this flexible as well?
-
Aug 4, 2003, 16:24 #7
-
Aug 5, 2003, 11:43 #8
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Beetle,
works great! Thanks very much.
Best regards,
Alex
Bookmarks