I've been staring at code all day, and I just can't seem to find what im looking for, I know how to do this with PHP but I'm new to dynamic stuff.
This code is inside a loop that is generated by a database. The dropdown items are fixed, but each individual is inside a database. I want to be able to choose the next drop down box selections based on the first one. This code works but not for each individual in the loop. Each item in the loop just updates the top one.
<div class="grid-container-fluid" style="margin-bottom: 25px;">
<div class="grid-container" style="font-family: 'Roboto Condensed', sans-serif;">
<div class="grid-x align-center">
<div class="large-10 cell">
<div class="grid-x">
<?php
if ($result->num_rows > 0) {
echo '<div class="large-12 cell">';
echo '<p style="font-family: Roboto Condensed, sans-serif; letter-spacing: 2px; font-weight: bold; line-height:1; font-size: 30px;">ADMIN PANEL:</p>';
echo '<p style="font-family: Roboto Condensed, sans-serif; font-size: 20px;">Income: $'.$total.'/mo<br>Program Value: $'.$value.'/person</p>';
echo '</div>';
echo '<div class="large-12 hide-for-small-only cell" style="border-bottom: 3px black solid; padding-bottom: 5px;">';
echo '<div class="grid-x">';
echo '<div class="medium-auto small-6 cell">';
echo '<p align="left" style="margin: 0;">NAME</p>';
echo '</div>';
echo '<div class="medium-auto small-6 cell">';
echo '<p align="left" style="margin: 0;">EMAIL</p>';
echo '</div>';
echo '<div class="medium-auto small-6 cell">';
echo '<p align="left" style="margin: 0;">PROGRAM</p>';
echo '</div>';
echo '<div class="medium-auto small-6 cell">';
echo '<p align="left" style="margin: 0;">PLAN</p>';
echo '</div>';
echo '<div class="medium-2 small-6 cell">';
echo '<p align="left" style="margin: 0;">STATUS</p>';
echo '</div>';
echo '<div class="medium-1 small-12 cell" style="padding-left: 15px;">';
echo '<p style="margin:0; text-align: center">';
echo '<i class="fi-wrench"></i>';
echo '</p>';
echo '</div>';
echo '</div>';
echo '</div>';
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<div class="large-12 cell" style="border-bottom: 1px black solid; padding: 5px;">';
echo '<div class="grid-x align-middle">';
echo '<div class="medium-auto small-12 cell" style="padding:2px;">';
echo '<input style="background-color: white; border: 0; margin: 0;" value="'.$row["name"].'" name="name">';
echo '</div>';
echo '<div class="medium-auto small-12 cell" style="padding:2px;">';
echo '<input style="background-color: white; border: 0; margin: 0;" value="'.$row["email"].'" name="email">';
echo '</div>';
echo '<div class="medium-auto small-12 cell" style="padding:2px;">';
echo '<select style="margin: 0; height: auto; border: 0;" name="program" id="program" onChange="changecat(this.value, '.$value.');">';
echo '<option value="" disabled selected>'.$row["program"].'</option>';
echo '<option value="Hockey">Hockey</option>';
echo '<option value="Fundamentals">Fundamentals</option>';
echo '</select>';
echo '</div>';
echo '<div class="medium-auto small-12 cell" style="padding:2px;">';
echo '<select style="margin: 0; height: auto; border: 0;" name="plan" id="plan">';
echo '<option value="" disabled selected>'.$row["plan"].'</option>';
echo '</select>';
echo '</div>';
?>
<script>
var programsByplan = {
Hockey: ["Off Season", "Pre Season", "In Season"],
Fundamentals: ["Phase 1"],
}
function changecat(value) {
if (value.length == 0) document.getElementById("plan").innerHTML = "<option></option>";
else {
var catOptions = "";
for (planId in programsByplan[value]) {
catOptions += "<option>" + programsByplan[value][planId] + "</option>";
}
document.getElementById("plan").innerHTML = catOptions;
}
}
</script>
<?php
echo '<div class="medium-2 small-12 cell">';
echo '<div class="grid-x align-middle">';
echo '<div class="small-6 cell">';
echo '<select style="margin: 0; height: auto; border: 0;" name="week">';
echo '<option value="'.$row["week"].'">' . 'Week ' . $row["week"] . '</option>';
echo '<option value="1">Week 1</option>';
echo '<option value="2">Week 2</option>';
echo '<option value="3">Week 3</option>';
echo '<option value="4">Week 4</option>';
echo '<option value="5">Week 5</option>';
echo '<option value="6">Week 6</option>';
echo '<option value="7">Week 7</option>';
echo '<option value="8">Week 8</option>';
echo '<option value="9">Week 9</option>';
echo '<option value="10">Week 10</option>';
echo '<option value="11">Week 11</option>';
echo '<option value="12">Week 12</option>';
echo '<option value="13">Week 13</option>';
echo '<option value="14">Week 14</option>';
echo '<option value="15">Week 15</option>';
echo '</select>';
echo '</div>';
echo '<div class="small-6 cell">';
echo '<select style="margin: 0; height: auto; border: 0;" name="day">';
echo '<option value="'.$row["day"].'">' . 'Day ' . $row["day"] . '</option>';
echo '<option value="1">Day 1</option>';
echo '<option value="2">Day 2</option>';
echo '<option value="3">Day 3</option>';
echo '<option value="4">Day 4</option>';
echo '</select>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="medium-1 small-12 cell" style="padding-left: 15px;">';
echo '<p style="margin:0; text-align: center">';
echo '<input style="font-size: 12px;" class="expanded button nav" type="submit" value="Update" name="submit" id="submit"/>';
echo '</p>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?>
</div>
</div>
</div>
</div>
</div>
I know it needs a unique id, I just can't figure out where.