Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filling array not working right

Status
Not open for further replies.

scuttleButt

Programmer
May 17, 2000
44
0
0
US
Could someone see what I am doing wrong? This SHOULD be soooo simple... but I am not strong in javascript.

I am trying to fill an array with numbers based on a string filled with 1's and 0's (selVal). If the first char is a "1" then the array needs to get a "1" added to it. If a char is a "0" then do nothing. If the 10th char is a "1" then the array needs to get a "10" added to it and so on. I have alertboxes in the code to see what is going on. I put an alert to see what selVal.length is and it is 22 which is what it is supposed to be. The alert in the for-loop is only showing once, like my for-loop isn't cycling 22 times. With my test data, the array should end up with something like: 1,10,11, 14,16,17,22. When the code runs, I get 1 and then the rest is undefined. Any clues??? Any help would be appreciated..

var arrComp = new Array();
for (var x=0; x<selVal.length; x++)
{
if (selVal.charAt(x)==&quot;1&quot;)
{arrComp[x]=(x+1);
alert(arrComp[x]);}
}

Much thanks!

ScuttleButt
&quot;Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months.&quot; ~ Clifford Stoll
 
Is selVal a string with quotes like &quot;10010101110101&quot;?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top