Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamically creating variable names in javascript

 
Timbu Buddu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic