Help coderanch get a
new server
by contributing to the fundraiser
  • 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

passing two arrays to Javascript function

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my JSP page, I have following code to generate two arrays from database
<%
User user = (User)request.getSession().getAttribute("user");
String id = user.getSSN();
VerificationDAO verDAO = VerificationDAO.getInstance();
ArrayList list = verDAO.findAllSessions(id);
int size = list.size();
String[] sessionValues = new String[size];
sessionValues = (String[])list.toArray(sessionValues);
String[] sessionLabels = verDAO.formatSession(sessionValues);
%>
now I have a dropdown list, when user select one of the option, I want my javascript function to create another dropdown list by using those two arrays as values and lables. How can I pass those two arrays to the function.
Here is the code
<tr>
<td colspan="2" align="left">
<html:select property="selectedVerification" onchange="InsertBox(sessionValues,sessionLabels)">
<html ption value="">--Please select a verification--</html ption>
<html ption value="0"> Scores Verification </html ption>
<html ption value="1"> Enrollment Verification </html ption>
<html ption value="2"> Semester GPA Verification</html ption>
<html ption value="3"> Degree Verification</html ption>
</html:select>
<div id="theSpot"/>
</td>
</tr>
I got run time errors by doing this. please help!
[ December 12, 2003: Message edited by: Eric Pascarello ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should first find a double combo script on a site like http://www.dynamicdrive.com
It will give you the prper javascript to use a double combo.
You then need to write out the array into the right sytax that the javascript can use.
Eric
 
Kan Qiu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make the question simple, How can I refer an array vaiable in my Javascript function ine the same JSP page. If you have an array String, How do I access the array from my Javascript function?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to write the array dynamiclally to the page.
There was a previous post on this topic, see if this helps you out.
https://coderanch.com/t/114070/HTML-JavaScript/initialize-js-array-java-array

Eric
 
Kan Qiu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have array dynamicly generated from JSP code,like this
<%
User user = (User)request.getSession().getAttribute("user");
String id = user.getSSN();
if (user.isDemoUser())
id = "483297701";
VerificationDAO verDAO = VerificationDAO.getInstance();
ArrayList list = verDAO.findAllSessions(id);
int size = (list==null?0:list.size());
String[] sessionValues = new String[size];
sessionValues = (String[])list.toArray(sessionValues);
String[] sessionLabels = verDAO.formatSession(sessionValues);
%>
I have two arrays. seesionValues and sessionLabels.
In my Javascript function InsertBox(). I don't know how to refer those two arrays. one question is, can I pass those two arrays as parameters? It seems I can not do that.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to dynamically write the arrays to the page between script tags in order for javascript to touch them and be able to handle them.
Javascript can not interact with server side code, it has to be all on the client side in order to work.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic