We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Passing varray elements(from JSP) to an array in javascript

nikhilbansal
nikhilbansal asked
on
Medium Priority
392 Views
Last Modified: 2008-02-01
Dear All,

I am supposed to display a menu which has sub - menus. The no of menus and sub - menus have to decided at run - time i.e. the entire data has to be populated from a table in a database.

One way of doing it can be getting the data into a varray from the table and then passing it to an array in javascript. Now, is it possible to pass a varray (from a JSP) to an array in javascript.

If this is possible then i need the code as early as possible.It's on an urgent basis.

Plz help

Regards

Nikhil Bansal
Comment
Watch Question

Commented:
You cannot 'pass' an array from JSP to JavaScript, but I think what you need to do is quite simple:

In your JSP

<script type="text/javascript">
var javascriptArray = [
<% for (int i = 0; i < jspArray.length; i++) { %>
<%= i == 0 ? "" : ", " %> '<%= jspArray[i] %>'
<% } %>
];
</script>

Author

Commented:
Dear All,

I have made a mistake in my question. Instead of vector I have written varray. This might be quite confusing.

I feel sorry for it. Actually I have been working on PL SQL  and Java and so I made this mistake.

Regards

Nikhil Bansal
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
Vector does not help. It is absolutely of no use. The vector value is valid only in the database access context. At next call it does not have no meaning in new process and new storage.

How did you want to reuse that vector pointer? What do you want to achieve? Could you use some record counter?

Commented:
<script type="text/javascript">
var javascriptArray = [
<% for (int i = 0; i < vector.size(); i++) { %>
<%= i == 0 ? "" : ", " %> '<%= vector.get(i) %>'
<% } %>
];
</script>

Commented:
I would like to raise one question:
 - Why not use jsp to build an html-based menu, using one of many good css-powered menu's?

Author

Commented:
Hi Zvonko

Cud u plz visit the site  http://www.softcomplex.com/products/tigra_menu/ and go there to the menu. There you can see below "Overview" a menu having "Menu Compatibility" etc. When i position my mouse over Menu Compatibility then it cascades to Supported Browsers,  Unsupported Browsers and Report Test Results.

Now for developing such a menu, they have hard - coded everything. I want it to be dynamic in nature.

My only question is tht can this dynamism be achieved for developing such a menu and if yes, then how ???

Plz visit the link provided as it will make the picture clearer.

Regards
Nikhil
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
I see that their demo/menu_items.js is highly structured and can be produced by your server side scripting as well.
And it need not to be placed outside the page in an extra file. You can embed your menu structure in a <script> section on your page.

Author

Commented:
Dear Zvonko

I visited the link http://www.likno.com/examples/example3.html. They are having a horizontal sub - menu.

I tried developing tht but cudn't succeed.

Cud u plz help.

I want the code which gives a horizontal sub - menu

Regards
Systems architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.