Oh. I see. I thought the "var" is really an option in JS. Now I know
that it has a function. Actually my last resort was to remove the
"onclick-confirm" part of the anchor but I wanted it to just change it
instantly when cake makes its own messages.

Thank you very much nwhite.

On Apr 16, 4:19 pm, nwhite <[email protected]> wrote:
> Inside your .each your creating an anonymous function for each anchor. The
> problem is your 'message' variable is not contained to that function. This
> is one of the messy details of javascript and not mootools specific. In
> order to keep the proper scope of your 'message' variable you need to add
> the keyword 'var' in front of it when you define it.
>
> var message = element.getProperty('onclick').split('\'')[1];
>
> Looking at your code you would also be better off using classes or some
> other non inline method for attaching.
>
> <a href="abc" class="confirm" rel="Activate">
> <a href="abc" class="confirm" rel="Deactivate">
>
> $$('a.confirm').each(function(el,idx){
>    var msg = el.get('rel');
>
> });
> On Thu, Apr 16, 2009 at 1:03 AM, eiji <[email protected]> wrote:
>
> > 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.

Reply via email to