Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to pass a parameter for a function parameter in a function

Reply
Thread Tools

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

 
 
AzamSharp
Guest
Posts: n/a
 
      07-04-2008

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.
 
Reply With Quote
 
 
 
 
SAM
Guest
Posts: n/a
 
      07-04-2008
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
 
Reply With Quote
 
 
 
 
SAM
Guest
Posts: n/a
 
      07-05-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pass function into another function as parameter? soni2926 Javascript 4 11-21-2008 05:40 PM
STL map compare function - can I pass a parameter? Martoon C++ 9 04-20-2006 12:11 PM
Javascript: is it possible to pass a parameter to a function inside a document write? Spartanicus HTML 4 10-07-2005 08:45 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments