Forum Moderators: open

Message Too Old, No Replies

multiple xmlhttp requests

         

JoJoJohnson

9:33 pm on Nov 16, 2007 (gmt 0)

10+ Year Member



I am trying to write a script which sends multiple xmlhttp requests but am having a couple of problems. Below is my code. I have stripped out a lot of stuff to make it as basic as possible

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]

JoJoJohnson

12:25 am on Nov 17, 2007 (gmt 0)

10+ Year Member



I think I've figured it out myself!

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!

JoJoJohnson

1:17 am on Nov 17, 2007 (gmt 0)

10+ Year Member



it worked!

I've got another problem now though! I'll create a different post for that one.