Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    32

    Unanswered: 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.

  2. #2
    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



    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.

  3. #3
    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

  4. #4
    Join Date
    Oct 2003
    Posts
    32

    thanks

    thanks Bagload.
    it worked!!!!

  5. #5
    Join Date
    Oct 2003
    Posts
    32

    thanks

    thnaks Bullschmidt for letting me know abt. that site!

  6. #6
    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, "'", "\'")

    Originally posted by srivalli9
    thanks Bagload.
    it worked!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •