Forum Moderators: open
Default.asp
===========
<script language="javascript">
function update()
{
for (intCount=0; intCount<form.checkbox.length; intCount++)
{
if (form.checkbox[intCount].checked==true)
{
sendData();
}
}
}
function sendData()
{
var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
xmlHTTP.onreadystatechange=function()
{
if(xmlHTTP.readyState == 4)
{
document.getElementById(intCount).innerHTML = xmlHTTP.responseText;
}
}
xmlHTTP.open("GET", "load.asp", false);
xmlHTTP.send(null);
}
</script>
<table border="1">
<form name="form">
<% for intCount = 0 to 5 %>
<tr>
<td>
<div id="<% =intCount %>">
<input type="checkbox" name="checkbox" value="<% =intCount %>" CHECKED>
</div>
</td>
</tr>
<% next %>
<tr>
<td><input type="button" value="Submit" onClick="return update()"></td>
</tr>
</form>
</table>
Load.asp
========
<% ="Done" %>
I am having 2 problems.
Firstly, it doesnt seem to make it all the way through to the bottom of the checkboxes. No matter how large I make my asp loop whether it be 5 or 30, it only seems to make it half way through the list.
Secondly, it doesnt always pick up when you have unchecked a box. Sometimes it will go ahead and make the xmlhttp request even if a box is unchecked.
Does someone know what's going wrong? I have been fiddling with the script for so long but can't figure it out!
[edited by: JoJoJohnson at 9:49 pm (utc) on Nov. 16, 2007]
It's becuase as I go through the for loop and replace the checkboxes with "Done" the array of checkbox items decreases so when it gets over half way through the loop, the index I pass through is no longer valid as there aren't enough checkboxes.
Haven't had the chance to write the corrected script yet, but would be good if someone could confirm this before I finish it!