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!

Make a function from a String

Status
Not open for further replies.

lmmoreira

Programmer
Jun 27, 2008
8
0
0
BR
Hello, I need your help please.

Do you know if there is any way to make a JavaScript function from a String.

For Example:

Here, there is a code of a function in the sString variable.

var sString = "function(){ alert('test'); }";

The Problem is here.
Is there any way to run the function in the sString variable

sString();

Thanks A Lot
 
Is this a student assignment? If so, please read the rules of this forum.

As for your question, do a Google search for "eval()". That should solve your problem.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top