By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,567 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,567 IT Pros & Developers. It's quick & easy.

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

P: n/a

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.
Jul 4 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SAM
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
Jul 4 '08 #2

P: n/a
SAM
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
Jul 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.