I have a plus button that when clicks updates some data in a db with php and then changes the button to a different image. When this happens though, the page always goes back to the top. Is there some way to stop that? The script I use now works if you hit f5, but does not work when you click an image button. Here is how the js flows. I'm posting it in logical order
Here's the html image
<img id="plus17" src="images/buttons/plus.png" onclick="plusClick('17')" style="border: none;">
heres plusClick note: GetXmlHttpObject creates a valid ajax object I can post that if you need, I'm just trying to keep this short
function plusClick(id){
xmlHttp = GetXmlHttpObject();
var url = "updateMessage.php";
url = url + "?id=" + id + "&action=positive";
url = url + "&sid=" + Math.random();
xmlHttp.onreadystatechange = function () { messageUp(xmlHttp.responseText); };
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}//plusClick
Here is updateMessage.php
note: runQuery connects to the db and executes the query. It works fine.
$query = "update messages set up = up + 1 where id = {$id};";
if(runQuery($query)){
echo($id);
}//if runquery
As you can see I echo the id and then in the messageUp function called by the previous js function changes my image src to a green image meaning they clicked it.
function messageUp(value){
if(value.length > 0){
document.getElementById("plus"+value).src = "Images/buttons/plusGreen.png";
}//if
}//messageUp