About using ArrayList inside javascript

Hi

In my JSP page I have an ArrayList which cantains names of people This ArrayList is populated once from database as the page loads. I have a textbox wherein user can enter a name. I am writing a javascript function onKeyUp event. What I would like to do is this -

as user goes on entering letters in the textbox this function should auto suggest names starting with the letters entered by searching in the ArrayList without submitting the page. Only place where I am facing problem is how will the javascript function use the ArrayList which is pure java code ?

Message was edited by:

aniketsakpal

[632 byte] By [aniketsakpala] at [2007-11-27 8:07:08]
# 1

The ArrayList data structure is part of your JSP code > Server side

The JavaScript code runs on the client side.

JavaScript is not Java, it only shares part of it's name.

What you could do is create a JavaScript datastructure by printing out the data from the ArrayList:

<%

//Create ArrayList

%>

function suggestNames()

{

var nameArray = new Array ( <%=//get first name here%>, <%=//get next name here%>, ...., <%=//get last name here% );

}

You could optimize in a few ways, but this should get you started.

nogoodatcodinga at 2007-7-12 19:49:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks a lot for the suggestion, I will try that out.
aniketsakpala at 2007-7-12 19:49:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...