Link to home
Start Free TrialLog in
Avatar of daveboyle99
daveboyle99

asked on

Mootools Ajax Help

Hi Guys,

I'm using the mootools 1.1 javascript library to create some nice AJAx effects on a search results page. Its all working but im having to loop through the window.addEvent function lots of times.

I wondered if anyone out there has the knowledge to compress this into one function, the sample contains 3 loops but there are often more.

D
window.addEvent('domready', function(){	$('resultpage1').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=1";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '1';
document.getElementById('From').innerHTML = '1';
document.getElementById('To').innerHTML = '10';
document.getElementById('CurrPageb').innerHTML = '1';
document.getElementById('Fromb').innerHTML = '1';
document.getElementById('Tob').innerHTML = '10';
document.getElementById('resultpage1').setAttribute("class", "current"); 
document.getElementById('resultpageb1').setAttribute("class", "current");
});	
});
window.addEvent('domready', function(){	$('resultpageb1').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=1";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '1';
document.getElementById('From').innerHTML = '1';
document.getElementById('To').innerHTML = '10';
document.getElementById('CurrPageb').innerHTML = '1';
document.getElementById('Fromb').innerHTML = '1';
document.getElementById('Tob').innerHTML = '10';
document.getElementById('resultpage1').setAttribute("class", "current"); 
document.getElementById('resultpageb1').setAttribute("class", "current");
});	
});
window.addEvent('domready', function(){	$('resultpage2').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=2";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '2';
document.getElementById('From').innerHTML = '10';
document.getElementById('To').innerHTML = '20';
document.getElementById('CurrPageb').innerHTML = '2';
document.getElementById('Fromb').innerHTML = '10';
document.getElementById('Tob').innerHTML = '20';
document.getElementById('resultpage2').setAttribute("class", "current"); 
document.getElementById('resultpageb2').setAttribute("class", "current");
});	
});
window.addEvent('domready', function(){	$('resultpageb2').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=2";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '2';
document.getElementById('From').innerHTML = '10';
document.getElementById('To').innerHTML = '20';
document.getElementById('CurrPageb').innerHTML = '2';
document.getElementById('Fromb').innerHTML = '10';
document.getElementById('Tob').innerHTML = '20';
document.getElementById('resultpage2').setAttribute("class", "current"); 
document.getElementById('resultpageb2').setAttribute("class", "current");
});	
});
window.addEvent('domready', function(){	$('resultpage3').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=3";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '3';
document.getElementById('From').innerHTML = '20';
document.getElementById('To').innerHTML = '30';
document.getElementById('CurrPageb').innerHTML = '3';
document.getElementById('Fromb').innerHTML = '20';
document.getElementById('Tob').innerHTML = '30';
document.getElementById('resultpage3').setAttribute("class", "current"); 
document.getElementById('resultpageb3').setAttribute("class", "current");
});	
});
window.addEvent('domready', function(){	$('resultpageb3').addEvent('click', function(e) {
e = new Event(e).stop();
var url = "paginate.php";
var postString = "page=3";
new Ajax(url, {method: 'get',data: postString,update: $('PaginateDiv')}).request();
document.getElementById('CurrPage').innerHTML = '3';
document.getElementById('From').innerHTML = '20';
document.getElementById('To').innerHTML = '30';
document.getElementById('CurrPageb').innerHTML = '3';
document.getElementById('Fromb').innerHTML = '20';
document.getElementById('Tob').innerHTML = '30';
document.getElementById('resultpage3').setAttribute("class", "current"); 
document.getElementById('resultpageb3').setAttribute("class", "current");
});	
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ziffgone
ziffgone
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of daveboyle99
daveboyle99

ASKER

thankyou