camilahlah 0 Newbie Poster

I need to get the values of all textboxes that I've generated through dropdown list using AJAX. I've been getting only the last value of the textbox, I can' seem to loop it. Anyway, here's my code:

<?
include('connect.php');

$tag = $_REQUEST['tag'];
$ProjectName  = $_REQUEST['ProjectName'];
$Description = $_REQUEST['Description'];
$textboxes = $_REQUEST['textboxes'];

if($tag=='A')
{

	//$insert = mysql_query("INSERT INTO tProject (ProjectName, Description, Pump) VALUES ('$ProjectName','$Description', '$textboxes')") or die (mysql_error());
	echo "Saved!";
}


?>
<html>
<head>
	
	<script type="text/javascript" src="ajaxhandler.js">

	</script>

</head>
<body>

<form method = "POST">

Project Name: 
	<input type="text" id="ProjectName"><br>

Description:
	<input type="text" id="Description"><br>

Pump:
<select name="boxes" onchange="Pump(this.value);">
	<option value="">choose</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
	<option value="10">10</option>
</select>
<div id='textboxes'>
</div>
<div id='textboxes1'>
</div>

<input type="button" onclick=chpage('AddP.php?tag=A') value="Save">
<input type="button" value="Clear">

</form
</body>
</html>

My AJAX code:

function chpage(url){ 
	var xmlHttp = getXMLHttp();
  
	        if ( url == "AddP.php?tag=A") 
		{
			var x= document.getElementById('ProjectName').value;
			var y= document.getElementById('Description').value;
		  	cn = document.getElementById( "textboxes" ).childNodes;
 			for (var i = 0; i < cn.length; i++) 
  			{  
    				var a = cn[i].value;
    				if(a==null)
    				{
    				}
    				else
    				{
    					var strURL = url + "&ProjectName=" + x + "&Description=" + y + "&textboxes=" + a;
    					
    				}
  			}
			
		}	 	

		else {
			var strURL =url;
		}
 
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
        HandleResponse(xmlHttp.responseText);
        document.getElementById('loading').style.visibility = "hidden";
      
    }
  }
	document.getElementById('loading').style.visibility = "visible";
	xmlHttp.open("GET", strURL, true);
	xmlHttp.send(null);
}

Any help would be very much appreciated. Thank you. =)

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.