scuttleButt
Programmer
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)=="1"
{arrComp[x]=(x+1);
alert(arrComp[x]);}
}
Much thanks!
ScuttleButt
"Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months." ~ Clifford Stoll
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)=="1"
{arrComp[x]=(x+1);
alert(arrComp[x]);}
}
Much thanks!
ScuttleButt
"Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months." ~ Clifford Stoll