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 2 of 2

Thread: function as URL

  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Question function as URL

    please, could you tell me the common syntax to give (for example) my function in 'ONCLICK' ,because there is a number of variants that i meet in my HTML book:
    onclick="functionname()";
    onclick=functionname(argument);
    onclick=functionname();

    I want to know which is the right variant in this confusion....????????

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Hi narek,

    Good day!

    The three ways are actually correct, but it's the first one that's perfect:
    Code:
    onclick="functioname()"
    or:
    Code:
    onclick="functioname(argument)"
    ...basically, because: Attribute values must be quoted at all times.

    The difference between: functionname() and functionname(argument) is that the latter is passing an "argument" to the function.

    An argument is the value that is passed from the program to the function call. This can also be considered as input to the function from the program from which it is called.

    To clearly see the difference, let's have this function as an example:
    Code:
    function functionname() {
    alert('This function is called with no argument');
    }
    ...now, if you passed an argument to the function, check this code:
    Code:
    function functionname(argument) {
    alert('This function has an argument and that argument is: '+argument);
    }
    You can also pass arrays as an argument, please check this article for more info:
    https://developer.mozilla.org/En/Cor...cope/Arguments


    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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