All,
I have the following div tag:
echo "<div id=\"txtHint".$resultsetstory['story_id']."\"><form>";
echo "<a href=\"viewcomments.php?story_id=$resultsetstory[story_id]\">(".$numcomments.") Comments</a> | ";
echo "Definite (".$resultsetvotes['vote_up'].") <img src=\"images/thumb_up.png\" alt=\"\" onClick=\"javascript:updatevotes($resultsetstory[story_id], 'Up');\"> | <img src=\"images/thumb_down.png\" alt=\"\" onClick=\"javascript:updatevotes($resultsetstory[story_id], 'Down');\"> I've heard worse (".$resultsetvotes['vote_down'].")";
echo "";
echo "</form>";
echo "</div>";
I have a javascript file to handle the onclick:
var xmlhttp;
function updatevotes(str, vote) {
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert("Browser does not support HTTP Request");
return;
}
var url = "updatestoryvotes.php";
url = url + "?id=" + str + "&vote=" + vote;
url = url + "&sid=" + Math.random();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
stateChanged(str,xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
function stateChanged(str, responseMsg) {
document.getElementById("txtHint" + str).innerHTML = responseMsg;
}
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
This all works fine. However when I change the div tag to:
<div id="txtSHint".$resultsetstory['story_id']."\">
and update the js file to:
function stateChanged(str, responseMsg) {
document.getElementById("txtSHint" + str).innerHTML = responseMsg;
}
It doesn't work, any ideas?
Also when I refresh the page the count is updated so I know the PHP page is working but for some reason it doesn't get back to the stateChanged() when I change the div id. I get an alert right before the stateChanged function but it never goes there. The only thing I changed is adding the S, it worked fine before that.