tags:

views:

164

answers:

4

I have an application where user can mention the transactions. The transaction must be mapped with some of the securities(Company name) that the user has already created. I want user to see the names of securities that he has created and as he starts typing, only the related securities must be visible.

Eg. If user types a, then all securities starting from a must be visible. Is there a way to do this?

A: 

To avoid using any ajax, you would need to load all the data into a javascript array when building the page in jsp.

Is this what you were envisioning? Would you like me to go further into implementation details or provide sample code for any part?

If you're looking to avoid jquery, this script does not have any dependencies (and has the option of using AJAX or JSON, so you would have the flexibility to change it in the future if you wanted).

Anthony DiSanti
How would I get the data into JavaScript array. The data is in database. Can you put some light on this.
Logan
You need to run a query for the securities you want to filter on, then write them into the document. I'll add the code in a followup response for working with an array, but the returned recordset is likely a very different data structure.
Anthony DiSanti
A: 

There is indeed. Something like the jqac plugin for jQuery would do the trick for you as it has a local mode that works with a pre-defined Javascript array.

Then all you'd have to do is use JSP to build that Javascript array on page rendering.

Pat
A: 

Looks like I can't do block code formatting in a comment, so I needed to make another answer:

You need to write an array literal into the document. I don't know Java, but it's gonna be something similar to:

out.write("<script>var JSSecurities = [");
for (int Security=0; Security<JavaSecurities.length(); Security++) {
  out.write("&'" + JavaSecurities[Security] + "',");
}
out.write("]");

For each is probably more appropriate there, but I don't know the syntax.

Anthony DiSanti
A: 

The easiest way to your goal here is AJAX. Imo. And to do it, I'd use JQuery.

Why do you want to avoid them?

Joshua Evensen