<select style="width:300px;" id="FirstDD" name="userListingCategory" onchange="FillSelectTwo(this.options[this.selectedIndex].value)">
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
unset($sth2);
$selectedOptionInCategory = $row['catID'];
?>
</select>
<select style="width:340px;" id="SecDD" name="userListingSCategory">
<option disabled="disabled">Sub-Category...</option>
<?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
When a 'category' is selected like:
I want the subcategories
associated with that first category
chosen to show up.
I'm running the following SQL:
SELECT scatID, scatName
FROM Category C, SubCategory SC
WHERE C.catID = SC.catID
AND C.catID = '$selectedOptionInCategory'
JS:
function FillSelectTwo(id) { //what is this id for?
$.ajax({
url: 'index.php',
dataType: 'text',
success: function(data) {
$('#SecDD').find('option').remove().end().append(data);
},
error:function(jxhr){
console.log(jxhr.responseText);
}
});
}
Problem I get
When I test this code out, I selected a category
like Baby, then the subcategory
box clears the first 'disabled' option value, but then its an empty set from there and I can't selected any of the values that the SQL
would return upon selecting a category
.
What it looks like: