alstefani
11-29-2008, 05:15 PM
Hi Guys!
I'm really bad with JavaScript (better in ASP). Can you tell me how to combine these 2 scripts in one? the only difference between the 2 is the ajax url call:
Here is the javascript:
function ajaxFunction1(){
var ajaxRequest1; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest1 = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest1.onreadystatechange = function(){
if(ajaxRequest1.readyState == 4){
var ajaxDisplay1 = document.getElementById('ajaxDiv');
ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
}
}
ajaxRequest1.open("GET", document.getElementById('First').getAttribute("href"), true);
ajaxRequest1.send(null);
}
function ajaxFunction2(){
var ajaxRequest2; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest2 = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest2.onreadystatechange = function(){
if(ajaxRequest2.readyState == 4){
var ajaxDisplay2 = document.getElementById('ajaxDiv');
ajaxDisplay2.innerHTML = ajaxRequest2.responseText;
}
}
ajaxRequest2.open("GET", document.getElementById('Previous').getAttribute("href"), true);
ajaxRequest2.send(null);
}
And here are the HTML trickers:
<table border="0" width="100%">
<tr>
<td><% If MM_offset <> 0 Then %><a href="<%=MM_moveFirst%>" id="First" onclick="ajaxFunction1();return false"><<First</a> <% End If ' end MM_offset <> 0 %></td>
<td><% If MM_offset <> 0 Then %><a href="<%=MM_movePrev%>" id="Previous" onclick="ajaxFunction2();return false"><Previous</a> <% End If ' end MM_offset <> 0 %></td>
</tr>
</table>
Please help!
I'm really bad with JavaScript (better in ASP). Can you tell me how to combine these 2 scripts in one? the only difference between the 2 is the ajax url call:
Here is the javascript:
function ajaxFunction1(){
var ajaxRequest1; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest1 = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest1.onreadystatechange = function(){
if(ajaxRequest1.readyState == 4){
var ajaxDisplay1 = document.getElementById('ajaxDiv');
ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
}
}
ajaxRequest1.open("GET", document.getElementById('First').getAttribute("href"), true);
ajaxRequest1.send(null);
}
function ajaxFunction2(){
var ajaxRequest2; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest2 = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest2.onreadystatechange = function(){
if(ajaxRequest2.readyState == 4){
var ajaxDisplay2 = document.getElementById('ajaxDiv');
ajaxDisplay2.innerHTML = ajaxRequest2.responseText;
}
}
ajaxRequest2.open("GET", document.getElementById('Previous').getAttribute("href"), true);
ajaxRequest2.send(null);
}
And here are the HTML trickers:
<table border="0" width="100%">
<tr>
<td><% If MM_offset <> 0 Then %><a href="<%=MM_moveFirst%>" id="First" onclick="ajaxFunction1();return false"><<First</a> <% End If ' end MM_offset <> 0 %></td>
<td><% If MM_offset <> 0 Then %><a href="<%=MM_movePrev%>" id="Previous" onclick="ajaxFunction2();return false"><Previous</a> <% End If ' end MM_offset <> 0 %></td>
</tr>
</table>
Please help!