Hi
Today I as working with some JavaScript code and had a function where the number of parameters would change in the runtime. Actually I had to do a validation where the number of textbox to equate the value for. I wanted to pass the array of textbox to the function.
But then I googled a bit and found a very nice feature of JavaScript which I had heard before. In JavaScript we can pass any number of parameter and get these parameter at run time.
JavaScript functions have a special property called arguments. these contain and array of the input parameters. we can use the length property of the array and loop through the parameters passed to the function. This enables the development of function where the number of parameters can change at runtime.
<SCRIPT Language="JavaScript">
function vikFunc()
{
var arguments = vikFunc.arguments;
for (var i = 0; i < arguments.length; i++)
{
alert("Argument number " + i + " value = " + arguments[i]);
}
}
</SCRIPT>
This function can be called with any number of arguments at the runtime like
vikFunc('Vikram', 'Lakhotia');
vikFunc('VikramLakhotia.com');
Thanks
Vikram