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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---