This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "dynamically creating variable names in javascript" Watch "dynamically creating variable names in javascript" New topic
Author

dynamically creating variable names in javascript

Timbu Buddu
Greenhorn

Joined: Apr 01, 2003
Posts: 8
Hi.
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: 1049
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:

cb
[ 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??
Thanks,


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.
Kishore.


Kishore
SCJP, blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamically creating variable names in javascript
 
Similar Threads
Dynamic Field Names using variable names
JavaScript Validation for data in HTML Tables
javascript database connectivity
How to write a javascript function to exapand/collapse all nodes in a TreeMenu
some java interview Questions