File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes dynamically creating variable names in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "dynamically creating variable names in javascript" Watch "dynamically creating variable names in javascript" New topic

dynamically creating variable names in javascript

Timbu Buddu

Joined: Apr 01, 2003
Posts: 8
I have to create variable names dynamically in JavaScript.
My JSP file accesses information from Database and forms a String corresponding to the information received.
This String is passed to a JAvaScript function that should CREATE a variable with that NAME.
For Ex:
My database access resulted in a single row...
id name sal
34 John Smith 38000
the resulting VARIABLE NAME should be Menu34. 34 comes from the database result.
Is there any function to dynamically create a variable name in JavaScript?
Thanks in advance.
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1061
If you are developing with JSP, JavaScript is just Text you print to the page, like HTML.
Given the JSP-Variable "id" containing the value "34" from your DB:

[ October 01, 2003: Message edited by: Chris Baron ]
Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
I have a situation that is similar, I'm getting values from the database, only I need the variables created in JSP, not Javascript. They are in a JSP file that I include in other JSP's, so the variables are referenced by name in those other files.
Do I have any hope??

Gail Mikels
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Jsp does support saving variables in different scopes. If you save for example in the session scope you are retrieve the parameter in other jsp pages as long as it is the same session.

SCJP, blog
I agree. Here's the link:
subject: dynamically creating variable names in javascript
It's not a secret anymore!