Hi Guys,
I'm relatively new here but I know stuff about Javascript and has been
starting on MooTools for quite some time. I have a question though on
how to pass variables on an anonymous function on domready. Well, I'll
post the code first so I can explain clearer.
window.addEvent('domready', function() {
/**
* Sexy Alert Box
*/
$$('a[onclick*=confirm]').each(function(element, index) {
message = element.getProperty('onclick').split('\'');
message = message[1];
element.removeProperty('onclick').addEvent('click', function
(event) {
event.stop();
Sexy.just_confirm(message, this);
});
});
});
I am using here a third party called Sexy Alert Box. Here in these
function I am trying to pass the "message" variable to the
Sexy.just_confirm function (just confirm is a function that I added to
the SexyAlertBox to have a straightforward and easy to apply change to
the normal javascript alert).
OK the problem. When I have lets say 4 anchors (ea)
a href="abc" onclick="return confirm('Activate?')"
a href="abc" onclick="return confirm('Deactivate?')"
a href="abc" onclick="return confirm('Activate?')"
a href="abc" onclick="return confirm('Deactivate?')"
What happens is that even if you click the first one, what pops up is
the "Deactivate" message cause when the loop on each element occurs,
the "message" variable is being replaced by the next loop, and at the
very end, the "message" is being changed. Now how do I pass each
anchors "message" to each individual function?
Wow.. err.. I hope I somehow explained it clear. Please do ask if I
need to clarify it more and I'll do my best. Is someone also using the
SexyAlertBox here? :)
Thanks.