mootools: how to pass a variable?

Joined
12 Feb 2006
Posts
17,627
Location
Surrey
ok this is very first time i am using mootools and i'm very lost with it so far so needing a quick bit of help.

i am playing around with the demos, this one at the bottom of the page, the morph to .myClass. I'm trying to alter it to work in different ways and so far i can get it to do simple things different.

now the problem i have is getting to to work for many different examples but only one at a time if that makes sense, so say i have box_44, box_32, box_39 if i clicked box_39 it only worked on box_39, box_32 it only works on box_32 etc. i have tried passing a variable to the function by the standard CSSmorphEffect(3) but mootools doesn't work with the typical onClick, the id of the element is just called CSSmorphEffect so i have no way of passing the function a variable as far as i can see.

anyone know how i can pass a variable to the function?
 
Last edited:
ah now i see (i think), ok knowing i can assign an event to any page element by referencing the id makes it much clearer now how to do it, i have done a quick test with random numbers and from what i can tell i can now alter it to work on the real page so thank you for the help pulseammo.
 
was hoping i wouldn't have to ask any more help but unfortunately i am.

been busy last few days but had a chance tonight to continue with this and got it so close to working just one small thing stopping me. the for loop i do with php works fine when displaying all the boxes, however the for loop i do with javascript does not, it's as though the loop doesn't exist as nothing ever happens with it. when writing each event separately then the effect works perfectly but not from the loop.

the code is pretty much exaclty as above,

PHP:
for(var i = 0; i < 20; i++ ){
 $('box_' + i).addEvent('click', function(e) {
        e.stop();
        // Changes the element's style to .myClass defined in the CSS
        $('box_' + i).morph('.myClass');
    });

}
any reason this would not work?
 
ok i have figured out the problem, well i believe i have. i think it was having difficulty with using the value of i from the loop as a character rather then a digit, atleast this is what i am thinking as when i put the script in the head section of the page itself and then used php to do the loop it then worked, nothing different except using $i instead of i.

i tried setting i as a var but it didn't mak a difference. anything else i can try?
 
Back
Top Bottom