Help with escape characters

J

john

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
 
M

Martin Honnen

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top