View Single Post
  #1 (permalink)  
Old 07-17-07, 04:39 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
AJAX Post an Array trouble

I have on my page several input boxes which i have in an array:

HTML Code:
    <td><input id="DealerShipBuddySites[]" type="text" size="40"></td>
    <td><input id="DealerShipBuddySites[]" type="text" size="40"></td>
    <td><input id="DealerShipBuddySites[]" type="text" size="40"></td>
    <td><input id="DealerShipBuddySites[]" type="text" size="40"></td>
    <td><input id="DealerShipBuddySites[]" type="text" size="40"></td>
If I do a normal post I get an array in $_POST['DealerShipBuddySites'] perfectly fine. But Im having trouble trying to post that array with AJAX. Below is my ajax code:

Code:
//Browser Support Code
function ajupdateform(){
	grayOut(true, {'zindex':'101', 'bgcolor':'#000000', 'opacity':'70'});
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajupdatediv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	var d1 = document.getElementById('DealerShipBuddySites').value;
	var queryString = "DealerShipBuddySites="+d1;
	ajaxRequest.open("POST", "test.php", true);
	ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; Charset=UTF-8');
	ajaxRequest.send(queryString);	
}
With the above Im getting "undefined" in d1 var. Now I know that getElementById is only ment to get one value so Ive seen getElementsByName but I cant get that to work too. Please help

Thanks
Reply With Quote