Second post on this project ... I am working on a bowling scoring system for a non-profit. They would like to be able to enter up to 9 games worth of scores into a form and have the shot results and game scores captured in a database. I have accomplished the scoring part with an html table/form combination. The last row of the table for each column is a Submit button for the user to click and send the shot results to the database using an Ajax call and then return a calculated score. I have worked through how to properly update the first div with this call.
Now I would like to also update a sidebar div that summarizes some data from all the games entered. I thought I could just include a second response statement with a different div id. So I tried:
function postData(url, parameters, divid1, divid2){
var xmlHttp = AJAX();
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
document.getElementById(divid1).innerHTML=loadingmessage;
}
if (xmlHttp.readyState == 4) {
document.getElementById(divid1).innerHTML=xmlHttp.responseText;
document.getElementById(divid2).innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parameters.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(parameters);
}
with a response file that looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<div>
<div id="resp3">
<?php
echo "divid1 response here";
?>
</div>
<div id="sidebar">
<?php
echo "divid2 response here";
?>
</div>
</div>
I have "resp3" and "sidebar" divs in my html which are passed to the Ajax function as vars divid1, divid2.
This all works except that both responses are returned to both divs.
How do I correctly update only divid1 response into "resp3" and divid2 response into "sidebar"?