473,770 Members | 6,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing a function name to another funtion

I have a system that I want to try, which requires me, from an aspx
page, to call a generic function to work perform one task, then i want
to call another function with the results of that task.

something like this:

in my aspx page:
<input type=button onClick="doFirs tFunction('seco ndFunctionName' );">

then in my .js file:

var functionToCall = '';

function doFirstFunction (functionName) {

functionToCall = functionName

// do the initial, common task
sResult = xmlHttp.respons eText

//now call the second function, passing sResult to it

}

Right now I'm using 'switch' and manually adding possible values for
'functionName' then directing manually, but I'd like to make
"doFirstFunctio n" self-maintaining, i.e. without having to update it if
I add more 'second' functions later.

I thought I could use

eval('functionT oCall('+sResult +')');

but this doesn't work so far.

any ideas?

Apr 21 '06 #1
17 8576
VK

Kevin Blount wrote:
I have a system that I want to try, which requires me, from an aspx
page, to call a generic function to work perform one task, then i want
to call another function with the results of that task.

something like this:

in my aspx page:
<input type=button onClick="doFirs tFunction('seco ndFunctionName' );">


Remove apos' and it will become ready to use function reference
(presuming that the secondFunctionN ame exists at the moment of click:
<input type="button" onclick="firstF unction(secondF unction);">
....
function firstFunction(p tr) {
// do stuff
ptr();
}

Alternatively (if you prefer handle strings) all existing functions are
tunelled through the window object, so:

<input type="button" onclick="firstF unction('second Function');">
....
function firstFunction(s tr) {
// do stuff
window[str]();
}

Apr 21 '06 #2
VK said the following on 4/21/2006 4:22 PM:
Kevin Blount wrote:
I have a system that I want to try, which requires me, from an aspx
page, to call a generic function to work perform one task, then i want
to call another function with the results of that task.

something like this:

in my aspx page:
<input type=button onClick="doFirs tFunction('seco ndFunctionName' );">
Remove apos' and it will become ready to use function reference
(presuming that the secondFunctionN ame exists at the moment of click:
<input type="button" onclick="firstF unction(secondF unction);">
....
function firstFunction(p tr) {
// do stuff
ptr();
}


ptr is undefined unless that is the name of the function.
Alternatively (if you prefer handle strings) all existing functions are
tunelled through the window object, so:

<input type="button" onclick="firstF unction('second Function');">
....
function firstFunction(s tr) {
// do stuff
window[str]();
}


That is the only way to do it that you have mentioned. And the apos'
have to be on the initial function call.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 21 '06 #3
VK

Randy Webb wrote:
function firstFunction(p tr) {
// do stuff
ptr();
}


ptr is undefined unless that is the name of the function.


Are you positive about it? ;-)

<html>
<head>
<title>F2F</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function f1(ptr) {
alert('f1');
ptr();
}
function f2() {
alert('f2');
}
</script>
</head>

<body>
<p style="cursor:p ointer; color:#0000FF; text-decoration:unde rline"
onClick="f1(f2) ;">Click me</p>
</body>
</html>

Apr 21 '06 #4
Randy Webb wrote:
<input type="button" onclick="firstF unction('second Function');">
....
function firstFunction(s tr) {
// do stuff
window[str](); <============== =====
}

That is the only way to do it that you have mentioned. And the apos'
have to be on the initial function call.


Could you please explain how this works? It seems like the answer to my
query (indirect function calls) but I don't see how that works.

Are entities (objects, whatever you call them) all elements in a window
array? (Sorry if this is newb Q; I am fairly new to javascript...)

--Yan
Apr 21 '06 #5
VK

Captain Dondo wrote:
Are entities (objects, whatever you call them) all elements in a window
array? (Sorry if this is newb Q; I am fairly new to javascript...)


They are "accessible as named properties of the window object" (I hope
that this diplomatic answer covers both IE and non IE situations wich
are rather different).
At the same time they are not enumerable.

The above means that having a conventional HTML page and function
called myFunction, you can call it in the conventional way:
myFunction();
and in the alternate way:
window["myFunction "]();

Apr 21 '06 #6
VK wrote:
Alternatively (if you prefer handle strings) all existing functions are
tunelled through the window object, so:

<input type="button" onclick="firstF unction('second Function');">
...
function firstFunction(s tr) {
// do stuff
window[str]();
}


Better:

// in global context
var _global = this;

function firstFunction(s tr)
{
// do stuff
_global[str]();
}

Both approaches require that secondFunction( ) is declared in global context,
of course.
PointedEars
Apr 21 '06 #7
VK wrote:
Captain Dondo wrote:
Are entities (objects, whatever you call them) all elements in a window
array? (Sorry if this is newb Q; I am fairly new to javascript...)

They are "accessible as named properties of the window object" (I hope
that this diplomatic answer covers both IE and non IE situations wich
are rather different).
At the same time they are not enumerable.

The above means that having a conventional HTML page and function
called myFunction, you can call it in the conventional way:
myFunction();
and in the alternate way:
window["myFunction "]();


OK< that sounds like what I need.... How do I test for existence of
such an entity?

if(window["myFunction ']) window["myFunction "](a,b,c);

??
Apr 21 '06 #8
VK wrote:
Captain Dondo wrote:
Are entities (objects, whatever you call them) all elements in a window
array? (Sorry if this is newb Q; I am fairly new to javascript...)
They are "accessible as named properties of the window object" (I hope
that this diplomatic answer covers both IE and non IE situations wich
are rather different).


It covers /only/ the _HTML environment_ in _known_ _graphical_
_Web browsers_, which is its major flaw.
At the same time they are not enumerable.
In the IE AOM.
The above means that having a conventional HTML page and function
called myFunction, you can call it in the conventional way:
myFunction();
and in the alternate way:
window["myFunction "]();


See news:35******** ********@Pointe dEars.de
PointedEars
Apr 21 '06 #9
VK

Thomas 'PointedEars' Lahn wrote:
VK wrote:
They are "accessible as named properties of the window object" (I hope
that this diplomatic answer covers both IE and non IE situations wich
are rather different).


It covers /only/ the _HTML environment_ in _known_ _graphical_
_Web browsers_, which is its major flaw.


The statement "window host object and Global object are the same"
covers only non-IE based browsers. The statement "Global object
tunells/peers its members through the window host object" covers
IE-based browsers. Both segments are too big to neglect, so an
"abstracted " yet correct explanation is better IMHO if it's not the
main question of the topic.

<offtopic>
Concerning some beloved spooky cases "Global object is here, but window
host is not": no one of them unfortunately is qualified to be taken
seriously.
Adobe SVG Viewer or Corel SVG Viewer are ancient and proprietary
plugins which are not more of anyone's concerns than say some
FoobarPlugin 0.01 behavior. Whatever happens where - it happens, and
thanks God if you come out alive :-)

And missing window host in a XSLT transformed page or a SVG page is not
a feature of the relevant formats, but a strong sign of a clueless
design. It just shows that the author still did not get that in XML the
used *parts* are not anyhow equal to the *resulted document*. In the
particular she may missed to tell in .xsl layout something like:
<xsl:output
method='html'
media-type='text/html'
version='4.01'
doctype-public='-//W3C//DTD HTML 4.01 Strict//EN'
doctype-system='http://www.w3.org/TR/html401/strict.dtd'
encoding='ISO-8859-1'
indent='no'/>
And again in this case no one is more responsible for the script
behavior than say in case of not closed properly <script> tag.

</offtopic>
At the same time they are not enumerable.


In the IE AOM.


As a reflection of Global/window differences in IE I started this post
with.

Apr 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14950
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
58
10181
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
0
3322
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems appear when someone is trying to use it as front-end for real server database systems such as PostgreSQL or MySQL. One of these problems is regarding pass-through queries and parameters. I wanted to have all the code on client, while executing it on...
4
5028
by: Pushkar Pradhan | last post by:
I want a function to execute another function, which I pass to it, sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style. double exec_basecase(void (*func)(double *a, double *b, double *c), double *a, double *b, double *c, int numRowsA, int numColsA, int numColsB) { ...../*other code*/ func(a, b, c); ..... }
2
1800
by: nagle.p | last post by:
Ok, Im writting a plug-in for a application and the class the I have to derive from has a warp() funtion that gets called that is part of the base class. I need to pass a varible into this funtion that has a sequence of numbers starting at (0,0) and going up to (nWidth, nHeight) which would be all the pixels on there screen at each coordinate. So I have tried all different types of things (pointers, functions inside the function call...
5
1945
by: Lee Xuzhang | last post by:
/* from SICP -- Exercise 4.21: ((lambda (n) ((lambda (fact) (fact fact n)) (lambda (ft k) (if (= k 1) 1 (* k (ft ft (- k 1))))))) 10) */
5
25130
by: steven_orocos | last post by:
Hi, I'm tryin to pass a funtion as an argument in another funtion. This code works ---------------------------------- typedef void (*func)(int); void test1(int a){cout<<"1";} void test2(int a){cout<<"2";}
13
2726
by: masso600 | last post by:
char word; in = fopen("test.txt", "r"); while(fscanf(in,"%s",&word)!=EOF) { /* Print all words */ /* printf("%s\n",&word); */
1
4890
by: shalabh6 | last post by:
Hi, A js file containing a function which is passing an alphanumeric string to another function in the same file, the second funtion requires 4 parameters to pass from the first function. The first three are the number and the last one is the alphanumeric string , but when I apply the fourth parameter , it throws out an error Expected';' The value in the varval parameter are like '2 xyz', '4 abc' The calling fucntion is being called...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.