PHP/HTML
<select id="n" name="userListingCateory">
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
unset($sth2);
?>
</select>
<select id="n" name="userListingSubCateory">
<option disabled="disabled">Sub-Category...</option>
<?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
This gives me correctly two dropdowns with values from database.
https://i.stack.imgur.com/s9rWB.png https://i.stack.imgur.com/4psBC.png (admin please show)
How do I get this (using JS or PHP) to make the ‘Sub-Category’ disabled until a ‘Category’ is selected, then based on the value chosen in Category, will enable the ‘sub-category’ dropdown to come up with the values pertaining to the category initially chosen??
The two database tables for category and subcategory are:
Category: catID (Pk)
catName
Subcategory: scatID (PK)
scatName
(admin please show images)
Anyone?
First of all, you are mixing two independant states and two critical parts of an application.
When a script is generated it is sent to the browser and then there is a downtime until the response comes back. But you seem to understand that.
The other critical part is to rip out the data logic from your script from the view part. No need to have any complex MVC framework to do that, just at least get your data for both parts in the top of your script will make it simpler.
Here is an approximate way to do it, adapt it to your technology or framework:
I hope this will get you started…
Good luck