• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Yongping Wang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bhuvana Madhav
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!