If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Creating variable names dynamically

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-01-03, 14:43
srivalli9 srivalli9 is offline
Registered User
 
Join Date: Oct 2003
Posts: 32
Creating variable names dynamically

Hi.

I have to create variable names dynamically in JavaScript.
My ASP 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.
Reply With Quote
  #2 (permalink)  
Old 10-01-03, 16:14
Bagload Bagload is offline
Registered User
 
Join Date: Oct 2003
Location: Glasgow, UK
Posts: 8
Re: Creating variable names dynamically

Sure there is

Code:
<snip setup connection etc.>
<script language="javascript">

<% Set objRs = objConn.Execute("SELECT id, name FROM tablename")
If Not objRs.EOF Then
   Do While Not objRs.EOF
      Response.Write "var Menu" & objRs.Fields(0).Value & " = '" & Replace(objRs.Fields(1).Value, "'", "\'") & "'" & vbNewLine
      objRs.MoveNext
   Loop
End If
objRs.Close %>
</script>
This will assign the variables value to be the name of the person.

HTH



Quote:
Originally posted by srivalli9
Hi.

I have to create variable names dynamically in JavaScript.
My ASP 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.
Reply With Quote
  #3 (permalink)  
Old 10-02-03, 01:52
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
You may want to ask more about this on a JavaScript board such as the one on this site or http://www.codingforums.com/forumdis...p?s=&forumid=2
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
  #4 (permalink)  
Old 10-02-03, 11:58
srivalli9 srivalli9 is offline
Registered User
 
Join Date: Oct 2003
Posts: 32
thanks

thanks Bagload.
it worked!!!!
Reply With Quote
  #5 (permalink)  
Old 10-02-03, 11:58
srivalli9 srivalli9 is offline
Registered User
 
Join Date: Oct 2003
Posts: 32
thanks

thnaks Bullschmidt for letting me know abt. that site!
Reply With Quote
  #6 (permalink)  
Old 10-02-03, 12:05
Bagload Bagload is offline
Registered User
 
Join Date: Oct 2003
Location: Glasgow, UK
Posts: 8
Re: thanks

Hi

I just noticed that my code was modified by the forum.

The Replace statement is replacing a single quote for backslash single quote. If one of the user's names had a single quote in it, that would cause a JS error.

Replace(objRs.Fields(1).Value, "'", "\'")

Quote:
Originally posted by srivalli9
thanks Bagload.
it worked!!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On