473,387 Members | 3,684 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,387 software developers and data experts.

for loop not working

Expand|Select|Wrap|Line Numbers
  1.             function startrun()
  2.                 {
  3.                     var n;
  4.                     var m;
  5.                     var p;
  6.                     var q;
  7.                     for(q=1; q<12; q++)
  8.                         {
  9.                             document.write(q);
  10.                             n="dcode"+q;
  11.                             m="acode"+q;
  12.                             if(document.getElementById(n).name==data[1]) && (document.getElementById(m).name==data[2])
  13.                                 {
  14.                                     p="d"+q;
  15.                                     document.getElementById(p).style.visibility="visible";
  16.                                 }
  17.                             else
  18.                                 {
  19.                                     p="d"+q;
  20.                                     document.getElementById(p).style.visibility="hidden";
  21.                                 }
  22.                         }
  23.                 }
So this is the code. I used the document.write to check if its incrementing, and i only get a value of 1. Removing the if statement makes it work... any idea? thanks..

Other info:
> It is an onload to the body.
> the acode[x] and dcode[x] are anchor objects.
Sep 8 '10 #1
1 1353
JKing
1,206 Expert 1GB
Hi there,

1) Remove/comment out the document.write. document.write forces a reload of the page and would clear your html. Use alert() instead for debugging because it doesn't cause a reload.

2) The brackets on your if statement are misplaced. You can have if(expression && expression) or if ((expression)&&(expression)) but not if(expression) && (expression)
Expand|Select|Wrap|Line Numbers
  1. //You have
  2. if(document.getElementById(n).name==data[1]) && (document.getElementById(m).name==data[2])
  3.  
  4. //Should look like this
  5. if((document.getElementById(n).name==data[1]) && (document.getElementById(m).name==data[2]))
  6.  
  7. //Or this
  8. if(document.getElementById(n).name==data[1] && document.getElementById(m).name==data[2])
  9.  
Sep 8 '10 #2

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

Similar topics

4
by: Ken Fine | last post by:
I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop, and it ain't working -- I'm getting a syntax error....
8
by: Drew | last post by:
I am building an application for keeping track of user permissions here at work. I have built the interfaces, and am now working on the processing page for inserting to the database. I am having...
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
5
by: L. Oborne | last post by:
I have this code working fine in Classic ASP but I get compile errors when I try to run it as ASP.NET. Do While NOT RS.EOF If ... Then... Else... End If RS.MoveNext Loop
10
by: Scott Richards | last post by:
Hi I am getting a exception while using a datareader here is the code Me.SqlConnection1.Open() Me.SqlReservationCheck.Parameters("@Ref").Value = Ref Dim Reader As SqlClient.SqlDataReader = _...
19
by: felixnielsen | last post by:
Some might remember that i, not so long ago, started a treath or two about a weird 3d labyrinth. I now have a working code, that i want to share, hear comments, advice, ect., but first let me...
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
2
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...
4
by: joaotsetsemoita | last post by:
hello everyone. Im trying to time out a loot after a certain time. Probably 5 to 10 minutes. I have the following function Private Sub processFileCreation(ByVal source As Object, ByVal e As...
1
by: Peter Duniho | last post by:
On Sat, 17 May 2008 16:36:17 -0700, <msnews.microsoft.comwrote: Sounds like a homework problem. Here's a hint: if you want your loop to go backwards, adding to (incrementing) the counter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.