I have a html form that posts the data to a php file for processing, on this form there is a dynamically produced combo box that is produced from a php file using javascript. The combo box displays and functions fine when the page is loaded but when the form is submitted the value from this box isn't posted.
the JavaScript function is
function showUser(str) {
if (str == "") {
document.getElementById("selSubCat").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("selSubCat").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getSubCats.php?Cat="+str,true);
xmlhttp.send();
}
}
The html is
<td >Category:</td>
<td >
<select name="Cats" onchange="showUser(this.value)" ><?
$qryCats="SELECT * FROM tblCategories";
$resCats=mysql_query($qryCats,$dbMain);
while($rowCats = mysql_fetch_array($resCats)){
echo "<option value='".$rowCats['Name']."'>".$rowCats['Name']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td >Sub Category:</td>
<td id="selSubCat">
</td>
</tr>
And the php file:
<?
include("dbconfig.php");
$cat=$_GET['Cat'];
$qryCats="SELECT * FROM tblSubCats WHERE Parent='" .$cat. "'";
$resCats=mysql_query($qryCats,$dbMain);
if ($numrow=mysql_num_rows($resCats)>0){
echo "<select name='subCats'>";
while($rowCats = mysql_fetch_array($resCats)){
echo "<option value='" .$rowCats['Name']. "'>" .$rowCats['Name']. "</option>";
}
echo "</select>";
}
else{
echo " There are no sub categories ";
}
?>
Any suggestions will be appreciated, I can't figure out why everything else apart from the subcategory is posted