Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   How to pass a parameter for a function parameter in a function (http://www.velocityreviews.com/forums/t936430-how-to-pass-a-parameter-for-a-function-parameter-in-a-function.html)

AzamSharp 07-04-2008 07:07 PM

How to pass a parameter for a function parameter in a function
 

function foo(msg)
{
alert(msg);
}



var insertForm = function()
{
this.button = $('add_customer');

this.button.observe('click', foo('hello world'));
}

The above line ' this.button.observe('click', foo('hello world'));'
does not really work. It will work if I don't pass any parameters.

SAM 07-04-2008 07:58 PM

Re: How to pass a parameter for a function parameter in a function
 
AzamSharp a écrit :
> function foo(msg)
> {
> alert(msg);
> }
>
>
>
> var insertForm = function()
> {
> this.button = $('add_customer');
> this.button.observe('click', foo('hello world'));
> }
>
> The above line ' this.button.observe('click', foo('hello world'));'
> does not really work. It will work if I don't pass any parameters.


perhaps :

var insertForm = function()
{
this.button = $('add_customer');
this.button.observe('click', function(){foo('hello world'))};
}

--
sm

SAM 07-05-2008 12:24 AM

Re: How to pass a parameter for a function parameter in a function
 
SAM a écrit :
>
> perhaps :
>
> var insertForm = function()
> {
> this.button = $('add_customer');
> this.button.observe('click', function(){foo('hello world'))};
> }
>



better :

var insertForm = function()
{
this.button = $('add_customer');
this.button.observe('click', function(){ foo('hello world') });
}


--
sm


All times are GMT. The time now is 04:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.