Hi,
I''m using prototype for a while now, but from the start I''ve
been
struggling with this. I obviously lack javascript knowledge. I hope
someone can show me the light... Here it comes.
I have a javascript function that creates and returns a button
element. The function has one argument, being a pointer to the
javascript function to call when the user clicks on the button. For
now it looks like this:
function getOkButton(clientOnClickFunction)
{
// create the image button
var button = new Element(''button'', {
className:''buttonBig'' });
button.appendChild(new Element(''img'', {
src:getApplicationPath() +
''img/ok.png''}));
// attach the click event handler
if (clientOnClickFunction != null)
Event.observe(button, ''click'', clientOnClickFunction);
return button;
}
Let''s say I have a page where I need an ''ok'' button.
Then I do
something like:
someElement.appendChild(getOkButton(clickHandler1));
function clickHandler1(event)
{
alert(''you clicked the first ok button'');
}
The thing I''m not able to figure out is how I can have that
clickHandler1 have more then only the event as an argument.
Now I''m _solving_ it like this (horrible):
clickHandler1.someInfoNeededInTheClickHandler = ''GO'';
someElement.appendChild(getOkButton(clickHandler1));
and the clickHandler1 looks like:
function clickHandler1(event)
{
alert(''you clicked the first ok button... info = '' +
clickHandler1.someInfoNeededInTheClickHandler);
}
This is ugly. And will give issues if I have 2 ''ok'' buttons on
1 page
which both should call clickHandler1, but with a different
''someInfoNeededInTheClickHandler''.
So basically my clickHandler1 should look like:
function clickHandler1(event, arg1, arg2, arg3)
{
// do something with arg1, arg2 and arg3
}
How can I solve this in a nice way?
Thanks in advance!
Manu aka TweeZz.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2008-Jan-17 13:22 UTC
Re: specifying function arguments when using Event.observe
Hey, It was discussed *yesterday*, man. Check the archives :-) What you''re looking for here, since you''re interested in keeping the event argument first, is bindAsEventListener: http://prototypejs.org/api/function/bindAsEventListener -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot! I tried look in the archives, but I didn''t find the correct search string probably... Really thanks a lot... On Jan 17, 2:22 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey, > > It was discussed *yesterday*, man. Check the archives :-) > > What you''re looking for here, since you''re interested in keeping the > event argument first, is bindAsEventListener: > > http://prototypejs.org/api/function/bindAsEventListener > > -- > Christophe Porteneuve aka TDD > t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---