All,
I’m working with this Ajax tutorial which basically pull some records from a database and display them. I want to modify the code with a button that will show the records one by one instead of together. The behavior I want to achieve is to get the next record each time the user clicks the Show next button.
To do that I have built a little counter in the Ajax function that is used as an index to decide which array element to print. This doesn’t work. **My question is: why doesn’t my counter work?
Here is the html and Ajax code:
<html>
<body>
<script type="text/javascript">
<!--
function createRequest() {
//Returns HttpRequest
return request;
}
//My attempt at a counter. This doesn't work.
var index=null;
function calcIndex(){
if(index==null){
index=0;
}else{
index += index;
}
return index;
}
(.....)
</body>
</html>
Your
calcIndexfunction declaration is broken, it’s missing thefunctionpart. And are you sure you want to setindex += index? That would be sort of odd. Not only that, even if you fix it and leave it as-is, index will never increment past zero:Let’s simplify:
But wait, at that point why do you need a function at all? Instead you can simply do:
Cheers