I've been playing with the interesting Behaviour JS script, which lets you use ID attributes to trigger events rather onclick events all through a page.

http://www.bennolan.com/behaviour/ for more info. But I have run into a problem with variable scope. In Behaviour, onload events go into an addLoadEvent function.

However the variables I am declaring on load aren't making it into the Behaviour action. The reason I need to get the function initialised in the onload is to hide a mootools slider.

Does anyone have any experience with behaviour/mootools and variable scope?


var myrules = {

   // Action occurs when button ID "test" is clicked
   '#test' : function(element){
	element.onclick = function(){
          // Basic moo AJAX
           var myform = $('myform');
	   var data  = myform.toQueryString();
           var myXHR =  new XHR({
               // Successful Ajax, display results
                   // PROBLEM!
                   // It can't see the variables I initialised in onload!
                   resultsDiv.setHTML(returnValue); // Not found
		   formeffect.toggle('vertical'); // Not found
	  }).send('ajax_action.php', data);

// Register the events

// Add onload events here.
Behaviour.addLoadEvent(function() {						

   // Setup mootools slider effect and hide the div	
   // This is where I do the initialising of the variables
   var resultsDiv = $('results');  
   var formeffect = new Fx.Slide(resultsDiv, { wait: false });