Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

toString? 1

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
0
0
GB
The following doesn't work but I include it to try and explain my blunder :p

I wish to output the value of a variable, in the followig case it should print <B>main</B> but it's important that it gets that value indirectly from the variable: sect :(

---
var page = 'main';
var sect = 'page';
document.write('<B>'+toString(sect)+'</B>');
---

----------
I'm willing to trade custom scripts for... [see profile]
 
Is the code called from a function, or from the global(window) level? Show the scenario in which it's called
 
If you can show it working inline then I can apply the fix :)

The 3 lines above are the bare bones of the scenario.

----------
I'm willing to trade custom scripts for... [see profile]
 

Maybe I've missed something, but wouldn't this work:

Code:
var page = 'main';
var sect = 'page';
document.write('<B>' + sect + '</B>');

I.E. removing the toString?

Dan
 
var page = 'main';
var sect = 'page';
document.write('<B>'+window[sect]+'</B>');
 
This will do the job...

var page = 'main';
var sect = 'page';
document.write('<B>'+eval(sect)+'</B>');
 
Cheers ggrabbit! :D

----------
I'm willing to trade custom scripts for... [see profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top