Click to See Complete Forum and Search --> : java array to javascript array


StyM
09-29-2003, 09:43 PM
hello Good Day.

i have a problem on how to pass a java string array to my javascript array.
i have this in my head.
<%
String strOnhand[] = new String[100];
int icounter = 0;
for ( int x = 0 ; x < 100 ; x++ ) {
strOnhand[x] = "Name" + String.valueOf(x);
}
%>

how can i pass this to my javascript array?
<script>
function test() {
var arr[] = ???????? <- i dont know how to do it???
}
</script>

need help badly, thanks in advance.

Khalid Ali
09-30-2003, 01:03 AM
how about looping thru your Java array and creating a js array

something like

<script>
var jsArray = new Array();
<%

for(int n=0;n<javaArray.length;n++){
%>
jsArray[<%=n;%>] = "<%=javaArray[n];%>";
<%
}

%>

</script>

There could be some Java related syntactical errors( I have not tested it),however,the logic should work

StyM
10-01-2003, 02:30 AM
Ok, thanks.
i'll try it.