hi all,
I am working on a small assigment but this code just wont work. I dont know what the problem is.
Can anyone please debug it.

var xmlhttp;
function listFriend(){
 xmlhttp = false;
	  /* For Firefox*/	  
      if (window.XMLHttpRequest) { 
         xmlhttp = new XMLHttpRequest();
      } else /*For IE*/
	     if (window.ActiveXObject) { 
         	try {
         	    /*For some versions of IE*/
            	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         	} catch (e) {
            	try {
            	  /*For some other versions of IE*/
               	  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
         }
      }
      if (!xmlhttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
     }
    var delfrnd = document.forms[0].elements["delFriends"].value;
    var url = "editFriends_ajaxing.php?delFriends="+delfrnd;
    alert(delfrnd+" "+url);
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = theResponse;
    xmlhttp.send(null);
    }
	//End showUserName
function theResponse(){
 	  alert("entering the function theResponse,readystate= "+xmlhttp.readyState+"status="+xmlhttp.status);
   	if(xmlhttp.readyState==4) {
   		if(xmlhttp.status==200) {
		 alert("inside the iffs");
			var xmlDoctext=xmlhttp.responseText;
			alert("xmlDoctxt is \n"+xmlDoctext);
   			var xmlDoc=xmlhttp.responseXML.documentElement;
			var rootElement=xmlDoc.documentElement;
			alert("xmldoc = "+xmlDoc);
            var htmlArray=[];//An array in which to accumulate HTML fragments in lieu of String += "....".
			htmlArray.push("<table border="1"><tr><th>Friend Name</th><th>Select to Delete</th></tr>");
			var length=xmlDoc.childNodes.length;
alert("htmlArray is \n"+htmlArray);	
			for(var i=0; i<length; i++) {
				alert("Entering the loop with readyState="+xmlhttp.readyState+"and status="+xmlhttp.status);
				var namenode = xmlDoc.childNodes[i];//refers to Friend
				alert("namenode is " + namenode.nodeValue);
				var sname=xmlDoc.childNodes[i].childNodes[0].childNodes[0].nodeValue;//refers to tag sender_username under this Friend tag
				alert("linkE is "+linkE);
				var rname=namenode.childNodes[1].childNodes[0].nodeValue;//refers to receiver_username under Friend
				var user=document.getElementById('userIN').value;
				var dspname="";
				if(user==sname){
					dspname=rname;
				}
				else{
					dspname=sname;
				}
				htmlArray.push("<tr><td>"+dspname+"</td></td>");
				alert("htmlArray is \n"+htmlArray);
				htmlArray.push('<td><input type="checkbox" name="delFriends[]" value='+dspname+'</td></tr>');
				
				/*var nameNo = namenode.childNodes.length;//refers to no of element under Name
				for(var j=2; j<nameNo; j++){
					//htmlArray.push();
					var Nam = namenode.childNodes[j];//1st object
					var sibl = Nam.childNodes[0];//its value
					if(sibl != null){ htmlArray.push("<td>"+sibl.nodeValue + "</td>"); }
					else{ htmlArray.push("<td>No Result</td>"); }
				}
				htmlArray.push("</tr>");
			}*/
  		htmlArray.push("</table>");
			alert("htmlarray = "+htmlArray.join(''));
			document.getElementById("tbl_deleteFriends").innerHTML = htmlArray.join('');
		}
		else{
   			alert('There was a problem with the request.'+xmlhttp.status);
   		}
	//removed "innerHTML+", and here we use Array.join to put the HTML fragments together
    }
}//END OF FUNCTION THERESPONSE


//The page where it is called
<?php 
	include('dbConnect.php');
	session_start();
	if(!session_is_registered(username)){
		header("Location: login.php");
	}
	$userLoggedIn=$_SESSION['username'];
	$resultAllFriends=mysql_query("select * from friends where (sender_username='$userLoggedIn' or receiver_username='$userLoggedIn') and approved='1'") or die("Cannot execute the query".mysql_error() );
	$numRows=mysql_num_rows($resultAllFriends);
?>
<html>
	<head>
	<script type="text/javascript" src="editfriend_ajax.js"></script>
	</head>
	<body>
		<form id="frm_editFriend" action ="" onsubmit="listFriend();return false;">
			<table border="1">
				<div id="tbl_deleteFriends">
					<tr><th>Friend Name</th><th>Select to Delete</th></tr>
					<?php while($rows=mysql_fetch_array($resultAllFriends)){
						if($rows['sender_username']==$userLoggedIn){
						$checkbox= $rows['receiver_username'];
					?>
					<tr><td><?php echo $rows['receiver_username']; ?></td>
					<?php
					} else {$checkbox= $rows['sender_username'];
					?>
					<tr><td><?php echo $rows['sender_username']; }?></td>
					<td><input type="checkbox" name="delFriends[]" value=<?php echo $rows['receiver_username'];?></td></tr>
			
					<?php 
						} 
					?>
				</div>
				<td><input type="submit" value="submit"/><td>
			</table>
		</form>
	</body>
</html>

On line 115 you missed a closing ">" for your checkbox. <td><input type="checkbox" name="delFriends[]" value="<?php echo $rows['receiver_username'];?>" [B]>[/B]</td></tr> Also, line 23 is wrong. The name of your element is NOT "delFriends". Use the exact name you gave the element

Hi try to use jquery for ajax. It will be easy to debug and also reduces the code size

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.