473,387 Members | 1,621 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.

Calling a javascript function with dynamic parameters

Hi,
I am looking to call a javascript function using variable number of
parameters.
Suppose I have a function
foo(param)
{
.....
}
I want it to be called unpredictebly when certain action occurs.
For example, I am using AJAX to make server call and get some data.
When I make the call, I also pass the name of my function in thi case
i.e. "foo". the server return some data and the name of the
client-function I originally passed in htis case i.e. "foo".
When the server call returns a callback funciton is invoked where I
process all data returned by server. Now when the callback function is
about the finish, I want it to call whatever function I passed to the
server, passing some data to it.

Any suggestion is highly appreciated.
Thank
--mayur

May 24 '06 #1
1 13133
ma***********@hotmail.com wrote:
Hi,
I am looking to call a javascript function using variable number of
parameters.
Suppose I have a function
foo(param)
{
....
}
I want it to be called unpredictebly when certain action occurs.
Not really sure what you're after here, but this seems to be related to
the -arguments- object.

Every function object has an arguments object that is created when the
function is called. arguments is a list of the arguments that were
passed to the function, each argument can be accessed by index.

<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Using_the_arguments_obje ct>

For example, I am using AJAX to make server call and get some data.
When I make the call, I also pass the name of my function in thi case
i.e. "foo". the server return some data and the name of the
client-function I originally passed in htis case i.e. "foo".
When the server call returns a callback funciton is invoked where I
process all data returned by server. Now when the callback function is
about the finish, I want it to call whatever function I passed to the
server, passing some data to it.


Are the parameters string literals or variables? i.e. are you trying to do:

foo('strVar0','strVar1','strVar2',...)

or

foo(var0,var1,var2,...)

or some combination of the above?

You might mean that if foo() makes the call, it can include its own name
in the data sent to the server. Later you want to call foo but you have
its name as a string, so somewhere in your code you have:

var funcName = 'foo';

// Later, call whatever function name was assigned to funcName:
window[funcName]();
Though it might be safer to do:

var funcRef = window[funcName];
if ('function' == typeof funcRef){
funcRef();
}

Assuming of course that foo() is a function declared with global scope.
If the script may run in some environment other than a browser, there
is a chance that there is no window object, so you'll want to use a more
generic reference to the global object. Right at the start of the
script do something like:

var _global = this;

then replace all instances of 'window' above with '_global'.

Does any of that help?
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 24 '06 #2

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

Similar topics

6
by: Edward King | last post by:
Hi! I am trying to achieve the following: I have a number of help pages (in the format help_nn.php where nn=helpid). I want to be able to open a particular help page by calling the function...
1
by: Miguel | last post by:
Hello. I have a Javascript function that validates an specific form. As parameters this function receives an array of elements to be checked. Depending on the form in cause, the array could have...
0
by: Venkat | last post by:
Hi All, I know that this is not right forum to address this issue, i had posted this problem in Javascript forum but of no use, i appreciate if any one of you can answer or point me to some...
1
by: Venkat | last post by:
Hi All, I am not able to access a dll function from a remote script using ActiveXobject when an output parameter is used, but i could able to access the same when no output parameter is used....
3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
5
by: Francesco Bochicchio | last post by:
Hi all, anybody knows if there is a (standard, portable) way to dinamically build a list of parameters to call a C function? Something like va_start & co, but to be used on the calling side? ...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.