473,653 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

For loop problem

132 New Member
Hi,

I'm making a script where I need a for loop to get the values out of selects and do a function on it. Except I don't know how to get those values out if there because the id of the selects are all different.

Here's a piece of the code.

Expand|Select|Wrap|Line Numbers
  1. <td>
  2. <select name="team1">
  3. <option value="1">1</option>
  4. <option value="2">2</option>
  5. <option value="3">3</option>
  6. </select>
  7. </td>
  8. <td><input type="text" name="score1" size="3"> - <input type="text" name="score2" size="3"></td>
  9. <td>
  10. <select name="team2">
  11. <option value="1">1</option>
  12. <option value="2">2</option>
  13. <option value="3">3</option>
  14. </select>
  15. </td>
  16. </tr>
  17. <tr>
  18. <td>
  19. <select name="team3">
  20. <option value="1">1</option>
  21. <option value="2">2</option>
  22. <option value="3">3</option>
  23. </select>
  24. </td>
  25. <td><input type="text" name="score3" size="3"> - <input type="text" name="score4" size="3"></td>
  26. <td>
  27. <select name="team4">
  28. <option value="1">1</option>
  29. <option value="2">2</option>
  30. <option value="3">3</option>
  31. </select>
  32. </td>
  33. </tr>
  34.  
And this is a part of the function:
Expand|Select|Wrap|Line Numbers
  1. for (var i=0; i<stand.length; i++)
  2. {
  3. if (document.klassement.team1.value == stand[i].name)
  4. {
  5. for (var k=0; k<stand.length; k++)
  6. {
  7. if (document.klassement.team2.value == stand[k].name)
  8. {
  9. stand[i].goalsm = parseInt(stand[i].goalsm) + parseInt(document.klassement.score11.value);
  10. stand[k].goalsr = parseInt(stand[k].goalsr) + parseInt(document.klassement.score11.value);
  11. stand[i].goalsr = parseInt(stand[i].goalsr) + parseInt(document.klassement.score12.value);
  12. stand[k].goalsm = parseInt(stand[k].goalsm) + parseInt(document.klassement.score12.value);
  13.  
  14. if (document.klassement.score11.value < document.klassement.score12.value)
  15. {
  16. stand[k].points = parseInt(stand[k].points) +3;
  17. stand[k].won = parseInt(stand[k].won) +1;
  18. }
  19.  
  20. else if (document.klassement.score11.value > document.klassement.score12.value)
  21. {
  22. stand[i].points = parseInt(stand[i].points) +3;
  23. stand[i].won = parseInt(stand[i].won) +1;
  24. }
  25.  
  26. else if (document.klassement.score11.value == document.klassement.score12.value)
  27. {
  28. stand[i].points = parseInt(stand[i].points) +1;
  29. stand[k].points = parseInt(stand[k].points) +1;
  30. }
  31. }
  32. }    
  33. }
  34. }
  35.  
Now the problem is that I'm executing this function on the first row of the table only, so I'm using team1, team2, score1 and score2.

But there are 8 more rows that I need to execute this function onto.
So I need to do the same for team3, team4, score3 and score4 and again for team5, team6, score5 and score6 and so on until I have done this function 9 times.

Now I could paste the entire function 9 times and just change the names manually but it's probably much easier to use a for loop to repeat it 9 times but I don't know how I could change my names.

So any help on this would be appreciated.

Greets,

Kenneth
Aug 21 '08 #1
3 1164
acoder
16,027 Recognized Expert Moderator MVP
Use the elements array, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.forms["klassement"].elements["team"+i].value
Aug 21 '08 #2
Cainnech
132 New Member
Indeed this solution works perfectly,

Thank you!
Aug 23 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Glad it worked :)
Aug 23 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2930
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 G23_NA17192.fsa rs7374540 A/C I23_Control.fsa rs7374540 C/C
5
8223
by: build | last post by:
G'day All, I have a problem with this loop. There are a number of .txt files in 'myPath'. tmpFile = Dir(myPath & "\*.txt") 'PROCESS FOLDER Do Until tmpFile = "" <lottsa code> <too much to post> tmpFile = Dir
11
19361
by: ritterhaus | last post by:
Just a simple bit of code to toggle between two state at intervals... import time for i in range(4): print 'On' time.sleep(1) print 'Off' time.sleep(1) .... SHOULD toggle On and Off four times with one-second pauses. When I
12
4889
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if (MenusToHoldOpen == menuName) { MenusToHoldOpen.splice(i,1); return;
43
5575
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 fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
63
3153
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
15
2669
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a "foreach" loop instead of a "for" loop. This made absolutely no sense to me, but the author had posted his code and timing results. The "foreach" (a VB and other languages construct) was 0.01 seconds to access 1000 lines in rich text box,...
2
2066
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with mysql. Same problem in Fx 2.0 and IE 7. I have the query sort of spread out across three pages to make it easier for me to generate it; I have a pagination script which checks what is being accessed from the query string (is it the whole blog or an...
5
4044
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
1
3036
by: JavaJon | last post by:
Hello, I'm Jon. I've recently picked up Java after using a "gimmick" programming language called GML ( Game Maker Language ). I've read a lot of tutorials and even a Java for Dummies *.pdf book. The basics are similar to what I'm accustomed to but there's still some confusion. I'm currently playing around with how the static, public, protected etc things work and I stumbled upon a problem. In the following copypasted code ( a tutorial I...
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2707
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 we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.