473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I call function that a variable refers to?

Hi. I'm wondering if there is a way to call function that a variable
refers to.

I was writing a script to load xml file.

And what I've written so far looks like this:

var xmlDoc;

function loadXML(xmlFile,xmlMethod)
{
if (document.implementation &&
document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("","",null) ;
xmlDoc.load(xmlFile);
xmlDoc.onload = ???????????;
} else if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(xmlFile);
????????????
} else {
alert("Your browser cannot handle the script.");
return;
}
}

I don't know how to process at '????????' part.

What I wanted to do was calling a function that xmlMethod variable
refers to.

Is there such a way to do it?

Thank you.

Regards,
Brian

Sep 2 '06 #1
5 40518


yaru22 wrote:
I'm wondering if there is a way to call function that a variable
refers to.
The same way you call any function e.g.
varName()
or e.g.
varName(arg1, arg2)

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 2 '06 #2
I tried as Martin said and that doesn't seem to work.

If what Martin said was true, then the following piece of code should
print "hello world":

var test="hi";

test();

function hi()
{
document.write("hello world");
}

================
However, when I tried it, it didn't work.

Does anyone know how to call a function that the value of a variable
refers to?

In the above example, since the value of the variable test is hi, I'd
like to call the function named hi().

Thank you.

Sep 2 '06 #3


yaru22 wrote:
I tried as Martin said and that doesn't seem to work.

If what Martin said was true, then the following piece of code should
print "hello world":

var test="hi";

test();

function hi()
{
document.write("hello world");
}
Pass a function and _not_ a string e.g.
var test = hi;
test();
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 2 '06 #4
Thank you so much Martin.

Thak works :D

Sep 2 '06 #5
yaru22 wrote:
var test="hi";

test();

function hi()
{
document.write("hello world");
}
To call a function with
it's string name ...

var test="hi";
window[test]();
function hi(){alert(test);}

Sep 2 '06 #6

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

Similar topics

9
by: iceColdFire | last post by:
HI, I have a function as void f(int p) { return p++; } now I have created a function pointer as
5
by: Lucy Randles | last post by:
I've written a VBA function that I then need to call in a form. Previously to do this I have written the call procedure in the same module as the function - i.e. Function callfunctionname() Call...
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
5
by: Jade | last post by:
I saw some web page saying I could do it this way in javascript: var iNumber = <%#publicvarname publicpropertyname %> but it doesn't seem to work. I have this piece of code here in...
2
by: moondaddy | last post by:
I'm using vb.net and have an aspx page where I want to call a function in the code behind to do something on the backend and I want to call this function from a jscript function in the aspx page. ...
12
by: leaf | last post by:
Hi, How to call function at runtime, based on a struct that contains the information for the function call: struct func_to_call { int function_id; // function id to call unsigned int nparams;...
1
by: SolitudeX | last post by:
Hey there, I have just started to learn the programming basics. Python looked like a good starting point! I have run into a little snag that I can't seem to find an answer for that I could use...
7
by: anto frank | last post by:
hi friends, is it possible to call a variable from the main function to a sub fuction with out sending as a argument, pointer and can't declare as global variable? void main() { int a=10;...
9
by: Andrew Poulos | last post by:
Say I have this: var foo = function(x, y) { return x + y; }; var bar = function(fname, param1, param2) { /* * how do I call the function "foo" * and pass parameters to it?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.