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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using variables in Array cell reference

Status
Not open for further replies.

NeeNee

Programmer
Apr 2, 2002
97
CA
I am trying to load an array in a loop as multiple ASP records ets are being generated.

For each record in the ASP recordsets, I want to load some values into an array which I can reference later.

This is what I have;
var ChildAttend = new Array()
var Array_Index = 0

ChildAttend[Array_Index, 0] =<%=Child_Index%>
ChildAttend[Array_Index, 1] =<%=rstChildAttend("LocationID") %>
ChildAttend[Array_Index, 2] =<% = rstChildAttend("VisitNum") %>

Array_Index = Array_Index + 1

I use the Array_Index variable as a type of row counter, except that my code does not insert the value of Array_Index but the text equivalent "Array_Index", which gives an error when the page is being loaded.

I have tried parseInt but that did not work. Why am I not able to get the value out of the variable? It works when I try to get the values out using a for loop.

Help please. I am starting to loose money on this contract.



Denis
Programmer, Canada
 
[tt]ChildAttend[Array_Index, 0] =[red]"[/red]<%=Child_Index%>[red]"[/red]
ChildAttend[Array_Index, 1] =[red]"[/red]<%=rstChildAttend("LocationID") %>[red]"[/red]
ChildAttend[Array_Index, 2] =[red]"[/red]<% = rstChildAttend("VisitNum") %>[red]"[/red]
[/tt]
 
Also looking again at the other lines, it is plain that when you loop, you loop at the server-side. Hence, you have to make Array_Index server-side variable, _not_ client-side.
[tt]
var ChildAttend = new Array()
<%
Array_Index=0
do while not rstChildAttend.eof
%>
ChildAttend[<%=Array_Index%>, 0] ="<%=Child_Index%>"
ChildAttend[<%=Array_Index%>, 1] ="<%=rstChildAttend("LocationID") %>"
ChildAttend[<%=Array_Index%>, 2] ="<%=rstChildAttend("VisitNum") %>"
<%
Array_Index=Array_Index+1
'other works...
rstChildAttend.movenext
loop
%>
[/tt]
 
Thanks, that worked. Now I have a different question.

I am declaring the array in the head section of my page, but loading it in the body as the page is being generated by ASP.

When I go to loop through the array after the page is complete, the values are not what they are supposed to be and the length of the array is wrong also. When I View the Source from my page, I can see the array being loaded. Is this because I am mixing head and body javascript


Denis
Programmer, Canada
 
The array should be in one piece. An important principle of debugging is not to doubt elementary/atomic established facts. Any apparant abberrations are due to wrongly applying those facts.
[tt]
<html>
<head>
<script language="javascript">
var a=new Array();
a[0]=0;
a[1]=1;
function checkit() {
alert(a.length);
}
</script>
</head>
<body>
<div>some division or for that matter any controls</div>
<script language="javascript">
a[2]=2;
a[3]=3;
</script>
<button onclick="checkit()">checking array in one piece</button>
</body>
</html>
[/tt]
 
Thank you,

The problem came with using a multidimensional array. I switched to 3 single arrays and it all works great.

Thanks again.

Denis
Programmer, Canada
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top