-
How do I get the selected ID for the second dropbox based on the first dropbox in PHP with a refresh?
over 4 years ago
-
over 4 years ago
Hi Laurens,
It seems like there are lot of issues in your example, I am not sure if the same code is working fine in your environment.
Anyway I am not going to point out all these errors and just trying to make your dropbox selection working. So for making selection part working, you have to make following changes:
1: Add name attributes to your dropboxes (select box)
<select id='subcatsSelect' name="subcatsSelect">
<select id='categoriesSelect' name="categoriesSelect">
2: Within your "if (isset($_POST['Ga'])) " condition, change the "if" condition and instead of echoing OPTION value, just store it's id:if ($row ['catid'] == $_POST['subcatsSelect']) {
$selectedId = $row['catid'];
}while ($row = $result->fetch_assoc()) {
if ($selectedId == $row['catid']) {
$resultofcat = "<option value='{$row['catid']}' selected='selected'> {$row['cat']}</option>";
} else {
$resultofcat = "<option value='{$row['catid']}'> {$row['cat']}</option>";
}
echo $resultofcat;
} -
1 Answer(s)