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

dynamic function

Status
Not open for further replies.

rube

Programmer
Dec 24, 2000
41
0
0
CA
There must be a simple solution, and I must be too tired to get it to work, but how does one call a function using a concatenated string?

I have a function:
SearchPage(){}

I have a string:
string="Search" + "Page";

I want to call the function!

Thanks.
 
Use a function literal and store it in a variable:

var searchPage = function(){};

then call the function with:

eval ("search+ "Page")()
 
Ooops ... make that:

eval ("search" + "Page")()

Sorry!
 
Thanks, man, I'll try that. I thought I had, but I gues I goofed it up. Had to check to see that I was on the right track.

Thanks again.
Rob
 
You can't evaluate a string. You should evaluate a variable containing a string. So you get:

FnString = "Search" + "Page";
Call(eval(FnString));

It is impossible to make anything foolproof because fools are so ingenious.
Murphy's Laws
 
Sorry, electraboy, but what I typed above works ... I'm not careless enough to put up solutions that don't. I tested the above before I posted it, and it works all right. Although I see your point, and shall remember it for future reference :)
 
rgstewart :
Sorry, you're right
I went to fast and i read it not accurate enough
sorry It is impossible to make anything foolproof because fools are so ingenious.
Murphy's Laws
 
Hey no worries - one solution is as good as the next ... so long as it works! Anyways, I think yours was a little neater :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top