Help with escape characters

Discussion in 'Javascript' started by john, Jun 24, 2004.

  1. john

    john Guest

    I am using Morten's JavaScript Tree Menu http://www.treemenu.com and i need
    to be able to put a node into the tree which is called

    'second level -23'

    which comes from a database

    The code goes like so

    var second_level_-23 = null;
    second_level_-23 = new MTMenu();
    second_level_-23.addItem('second level - 23'..........

    I need to do something to the - in the middle of the string. Can anyone
    tell me how to convert 'second level -23' to a legal name for a javascript
    var. I am building the tree dynamically so need to write the replacement
    string in VB to pass to the completed script.

    Many thanks

    John
     
    john, Jun 24, 2004
    #1
    1. Advertising

  2. john wrote:


    > var second_level_-23 = null;
    > second_level_-23 = new MTMenu();
    > second_level_-23.addItem('second level - 23'..........


    If that is a global variable then do
    window['second_level-23'] = new MTMenu();
    window['second_level-23'].addItem('second level - 23'..........
    Otherwise use an object e.g.
    var levels = {};
    levels['second_level-23'] = new MTMenu();
    levels['second_level-23'].addItem('second level - 23'..........

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Griff

    trying out escape characters

    Griff, Aug 3, 2004, in forum: Perl
    Replies:
    6
    Views:
    611
  2. Maziar Aflatoun

    Escape characters

    Maziar Aflatoun, Dec 5, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    564
    Jason S
    Dec 5, 2003
  3. Guadala Harry

    What Happens To Escape Characters?

    Guadala Harry, Aug 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    701
    Lau Lei Cheong
    Aug 19, 2004
  4. =?Utf-8?B?YmFzdWxhc3o=?=

    Are there escape characters for SQL?

    =?Utf-8?B?YmFzdWxhc3o=?=, Jul 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    10,951
    Patrice
    Jul 7, 2005
  5. slomo
    Replies:
    5
    Views:
    1,570
    Duncan Booth
    Dec 2, 2007
Loading...

Share This Page