Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function parameter help

    I am having a little trouble with the function parameter, I dont know what it does exactly, could anyone explain it?

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With a parameter, you can insert values. Say you want to create a function that will add two values...

    PHP Code:
    function add(var a, var b){
      
    c;
      return 
    c;

    Then you could use the function like...

    PHP Code:
    document.write(2,2); 
    This would output 4

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts

    paramaters

    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';

    alert(a+b);
    }

    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){
    alert(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.
    Last edited by brandonH; 07-09-2006 at 11:22 PM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •