If there are 10 records the form gets prepared for the 10 records. So i only select a few options and enter some values when i click on save link, only the first record is saved while the rest are ignored rather stops at that.
Code snippets:
Javascript snippet
function save_reg(records){
//called from multi-add form
var str;
var counter=0;
var myDate = document.getElementById('tdate').value; //extract the date
if(myDate!=''){
for (foo= 1; foo < records+1; foo++) {
var Id = 'mid'+ foo;
var Stats = 'stats'+foo;
var Att = 'attendance'+foo;
agentId = document.getElementById(Id).value;
agentStats = document.getElementById(Stats).value;
agentAtt = document.getElementById(Att).value;
str = "agentId=" + agentId + "&agentStats=" + agentStats + "&agentAtt=" + agentAtt + "&wDate="+myDate;
if(agentId!="" && agentStats!="" && agentAtt!="--Status--"){
requestInfo('workRoll.php?mode=save&'+str, 'showTable', '');
document.getElementById(Stats).style.backgroundColor="#33FF00";
document.getElementById(Att).style.backgroundColor="#33FF00";
}else{
document.getElementById(Stats).style.backgroundColor="#FF0000";
document.getElementById(Att).style.backgroundColor="#FF0000";
counter++;
}
}
php/html code snippet
while($row=$obj->query_fetch(0)) {
$recNum++;
$id=$row["rollNumber"];
$names=$row["Names"];
echo "<tr bgcolor='#ffffff'>";
echo "<td><input type=\"text\" id='mid$id' value=\"$id\" readonly='readonly' size='10'></td>";
echo "<td><input type='text' id='names' value='$names' readonly='readonly' size='20'></td>";
echo "<td> <select name='attendance' id='attendance$id'>
<option>--Status--</option>
<option value='Absent'>Absent</option>
<option value='Present'>Present</option>
<option value='Off Day'>Off Day</option>
</select></td>";
echo "<td><input type='text' id='stats$id' size='10'></td>";
echo "</tr>";
}
echo "<tr bgcolor='#eeeeee'>";
echo "<td align='center'><a href='#'>Reset</a></td>";
echo "<td align='left'><a href=\"javascript:save_reg($recNum)\">Save</a></td>";
more javascript...
function requestInfo(url,id,redirectPage) {
var temp=new Array();
//alert redirectPage;
http.open("GET", url, true);
http.onreadystatechange = function() {
if (http.readyState == 4) {
if(http.status==200) {
var results=http.responseText;
if(redirectPage=="" && results!="") {
var temp=id.split("~"); // To display on multiple div
//alert(temp.length);
var r=results.split("~"); // To display multiple data into the div
//alert(temp.length);
if(temp.length>1) {
for(i=0;i<temp.length;i++) {
//alert(temp[i]);
document.getElementById(temp[i]).innerHTML=r[i];
}
} else {
document.getElementById(id).innerHTML = results;
}
} else {
//alert(results);
window.location.href=redirectPage;
}
}
}
}
http.send(url);
}
What could be the problem??