Forums Register Login

How to pass array (string) data into a javascript funtion

+Pie Number of slices to send: Send
Hi,
Here is a situation. There is a String array generated by a javabean (declared in a jsp page). I am thinking of passing the array data into a javascript function (which is embedded the jsp page) but not sure if it is possible. Please shed your light on it. I appreciate it very much.
Yongping
+Pie Number of slices to send: Send
Hi
This is one way to implement the array in javascript.Here the jspclient is the array avaliable in jsp and htmlclient is the array to be created in javascript.
<%
out.println("<script>");
out.println("var htmlClient=new Array("+ jspClient.size()+");");
out.println("function filterClient()");
out.println("{");
out.println("var doc=document.forms[0];");
out.println("doc.client.options.length = 0;");
out.println("for(i=0,j=1;i<htmlClient.length;i++)");
out.println("{");
out.println("doc.client.options[j++] = new Option("+jspClient[i][1]+","+jspClient[i][0]+")");
out.println("}");
out.println("}");
out.println("</script>");
%>
I hop this will be usefull to U
Regards,
Bhuvana
It's feeding time! Give me the food you were going to give to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1144 times.
Similar Threads
Array values display problem
How to write retrieved data into javascript Array?
passing two arrays to Javascript function
Pass Array from servlet program to JavaScript
md5 jsp javascript
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:44:31.