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

A

AzamSharp

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.
 
S

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'))};
}
 
S

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top