next up previous
Next: Some Useful JavaScript Functions Up: Functions Previous: Functions

Parameter Passing

Simple Example:

function about_you(name, age, shoesize){
     document.write("<h1>All About You</h1>");
     document.write("<p><strong>Your Name is:
          </strong>" + name);
     document.write("<p><strong>You Are</strong>"
           + age + "Years Old");
     document.write("<p><strong>Your Shoe Size is:
           </strong>" + shoesize);
}

That might be called like this as the page is loaded:

<html>
<head>
  <script language="javascript">

   function about_you(name, age, shoesize){
      document.write("<h1>All About You</h1>");
      document.write("<p><strong>Your Name is:
                     </strong>" + name);
      document.write("<p><strong>You Are</strong>"
                   + age + "Years Old");
      document.write("<p><strong>Your Shoe Size is:
              </strong>" + shoesize);
  </script>
</head>
<body onLoad="about_you('David', 37, 9)">
</body>
</html>

or simply like this from within another function of more complex script:

function another_function() {
  ......
  about_you('David', 37, 9);
  ......
}

How are parameters passes into to functions in JavaScript?

This is not what you might expect?



Dave Marshall
9/28/2001