spacer.png, 0 kB
spacer.png, 0 kB
Home arrow Javascript arrow Javascript: passing arguments to a function
Javascript: passing arguments to a function PDF Print E-mail
Written by Administrator   
sabato, 23 agosto 2008

Javascript functions have a special property containing an array of the parameters passed.
This property called arguments can be handled to adapt the function, that can then changes depending on the arguments.

The example here below prints in alert all the parameters:

<SCRIPT Language="JavaScript">

function function1() {
   var argv = function1.arguments;
   var argc = argv.length;
   for (var i = 0; i < argc; i++) {
     alert("Argument" + i + " = " + argv[i]);
   }
}
</SCRIPT>

You can call the function with the below code:

<SCRIPT Language="JavaScript">

  function1('parametro1','parametro2');
</SCRIPT>

Last Updated ( sabato, 23 agosto 2008 )
 
< Prev   Next >
spacer.png, 0 kB
spacer.png, 0 kB
spacer.png, 0 kB