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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute a string in JavaScript

Status
Not open for further replies.

Pesho318i

Programmer
Jun 16, 2006
13
NL
Hi all,

I have a long string with JavaScript functions, e.g.
string = "document.write(\"Hello\")";

I'd like to execute this string in JavaScript. How can I do this?


thanks,
Pesho

 
With the dreaded eval function.
*(disclaimer: use of eval function is not recommended)
Code:
string = "document.write(\"Hello\")";
eval(string)

I'm going to bet there is a better way to do what you are wanting though.

[monkey][snake] <.
 
Hi

Code:
string = "document.write(\"Hello\")";
[red]eval(string);[/red]
[ol]
[li]I would use variable name more different by the class name[/li]
[li]I would use [tt]eval()[/tt] only if no other solution is possible[/li]
[/ol]

Feherke.
 
You 2 should get a room [love]



[lol]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Sorry for interrupting you, but maybe you should consider updating your innerHTML instead of eval.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top