
Passing Server Side Arrays to Client Side Scripts
The best way to do this is to pre-load the server-side array into a
client-side array when the server-side ASP is processed. Then you can have
your client script to anything you want with the client-side copy of the
array.
To do this iterate the server-side array in server-side ASP script and build
the client-side array in the server-side loop. Here's a quick example in
VBscript:
<%
'Declare the server-side array and some variables
dim arrServer(2)
dim intArrSize
dim n
intArrSize=UBound(arrServer)
%>
<!-- Create a mirror client-side array with the same size as the server-side
array-->
<script language="vbscript">
dim arrClient(<% =intArrSize %>)
</script>
<%
'Populate the array server-side with some sample data
arrServer(0)="Wibbly"
arrServer(1)="Wobbly"
arrServer(2)="Woo"
'Loop the server-side array
for n=0 to intArrSize
%>
<!-- Insert the server-side array data into the client-side array -->
<script language="vbscript">
arrClient(<% =n %>)="<% =arrServer(n) %>"
</script>
<%
next
%>
<!-- Display the client-side array so we know it worked -->
<script language="vbscript">
dim n
for n=0 to UBound(arrClient)
alert(arrClient(n))
next
</script>
Hope this gives you some ideas.
--
Aunty Dan (Remove X from Hotmail to reply directly)
Quote:
> Does anyone know who to retrieve a server side dimensioned array from the
> client side using vbscript? I basically want to execute some vbscript on
> the onclick() event of a button that recursively reads in data from a
server
> side array. Any help is appreciated. Thanks in advance.
> Thuan Tran