View Full Version : function parameter help

07-09-2006, 11:06 PM
I am having a little trouble with the function parameter, I dont know what it does exactly, could anyone explain it?

07-10-2006, 12:01 AM
With a parameter, you can insert values. Say you want to create a function that will add two values...

function add(var a, var b){
a + b = c;
return c;

Then you could use the function like...


This would output 4

07-10-2006, 12:15 AM
a function paramater is basically a way of passing a value to a function via variable.

as i am sure you already know you can set variables within a function:

function YourFunction(){
var a='something';
var b='else';


well paramaters are,sa i said before, basically variables passed to the funtion.

<a href=#stayhere onclick="YourFunction2('first', 'one');" >click here</a>
<a href=#stayhere onclick="YourFunction2('second', 'something');" >click here</a>
<a href=#stayhere onclick="YourFunction2('third', 'value');" >click here</a>

the above html for a link refrences to the function YourFunction2().
the function would look something like this:

function YourFunction2(a,b){

notice i put a,b within the ( ). this defines a set name to the paramaters.
when you pass ('something', 'else') to the function it assigns a variable name to the value of the string you passed to it so that it can use it. So when the function uses " a " it is grabbing the value of the paramater " a ". the first link sets the variable ' a ' to "first".

instead of setting variables within the function , you are now setting them from outside the function. this allows you to use your script for more than one thing. As you can see ther are 2 other links passing paramaters to the same function. Each link, when clicked, will give you a different outcome from the function.