• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic