Use functionName.arguments to reference the arguments : Function Parameters « Function « JavaScript Tutorial






<HTML>
<HEAD>
   <TITLE>
   Add all of the numbers
   </TITLE>
   <SCRIPT>
   function addNums () {
      var theAnswer = 0;
      for (var i = 0; i < addNums.arguments.length; i++) {
         var theNum = Number(addNums.arguments[i]);
         theAnswer += theNum;
      }
      return theAnswer;
   } 
   </SCRIPT>
</HEAD>
<BODY>
<FORM Name="theForm">
<INPUT Type=Text Name="num1">
<INPUT Type=Text Name="num2">
<INPUT Type=Text Name="num3">
<INPUT Type=Text Name="num4">
<INPUT Type=Button 
Value="Add Them" 
onClick='document.write(addNums(theForm.num1.value,theForm.num2.value,theForm.num3.value,theForm.num4.value));'>
</FORM>
</BODY>
</HTML>








7.3.Function Parameters
7.3.1.Pass value to a function
7.3.2.Pass number to a function
7.3.3.Pass integer to function
7.3.4.Pass Form value to a function
7.3.5.Use functionName.arguments to reference the arguments
7.3.6.Pass an array to a function