I think the worst part of your code is that onclick
attribute inside the <a>
tag.
Since you're using jQuery in your code, you sure should use it to bind/unbind click handlers to DOM elements without those messy html attributes.
HERE'S HOW YOU CAN TRIGGER YOUR FUNCTION ONCLICK
$("#previous a").click(function(e){
// this is so it prevents the default
// behavior of an anchor redirecting to href
e.preventDefault
// triggers the function. I imagine you have a
// pagesLeft counter that will count down
getBusinesses(pagesLeft)
})
NOW MODIFY YOUR JS FUNCTION TO UNBIND THE HANDLER WHEN pagesLeft RECHES 0
var pagesLeft = 3 // any you need, you get from somewhere
function getBusinesses(page){
if(page==0){
alert("you are already on First Page");
// See here i use jQuery .unbind('click')
$("#previous a").unbind('click');
}
else{
pagesLeft--
$.ajax({
type: "POST",
url: "getbusiness.php",
data: "page="+page,
success: function(msg)
{
$("#new2").html(msg);
}
});
}
}
EDIT
As a whole so you see the full changes
<div id="new34" style=" width:1028px; height:15px; background#fff; float:left;">
<div id="previous" style="float:left; width:20px;">
<a href="#"><</a><!-- see here no onclick and href="#" -->
</div>
</div>
var pagesLeft = 3 // any you need, you get from somewhere
function getBusinesses(page){
if(page==0){
alert("you are already on First Page");
// See here i use jQuery .unbind('click')
$("#previous a").unbind('click');
}
else{
pagesLeft--
$.ajax({
type: "POST",
url: "getbusiness.php",
data: "page="+page,
success: function(msg)
{
$("#new2").html(msg);
}
});
}
}
$("#previous a").click(function(e){
// this is so it prevents the default
// behavior of an anchor redirecting to href
e.preventDefault
// triggers the function. I imagine you have a
// pagesLeft counter that will count down
getBusinesses(pagesLeft)
})
LAST EDIT
If you want to keep your original code here's how it'd look, although it has some major holes in it
<div id="new34" style=" width:1028px; height:15px; background#fff; float:left;">
<div id="previous" style="float:left; width:20px;">
<!-- how do you set getBusinesses(1) with 1 as argument? -->
<a onclick="getBusinesses(1)" href="javascript:void(0)">aaa</a></div>
<script>
function getBusinesses(page){
if(page==0){
alert("you are already on First Page");
$("#previous a").removeAttr("onclick");
}
else{
// Here you should decrement the argument of getBusinesses
// but how do you do it?
$("#previous a").attr("onclick","getBusinesses(0)");
$.ajax
({
type: "POST",
url: "getbusiness.php",
data: "page="+page,
success: function(msg)
{
$("#new2").html(msg);
}
});
}
}
</script>
HERE THE FIDDLE FOR THIS LAST EDIT