javascript - on change jquery only works once for db values -
i have 3 select boxes ids first-choice, second-choice , third choice.
<select id="first-choice" style="border-radius: 0; width: 100%;" class="form-control" name="area"> <option value="">-select-</option> <option value="">all</option> <?php global $connection; $area_query = "select distinct area archivo length(area) > 1"; $result_area = mysqli_query($connection, $area_query ); while($row_a = mysqli_fetch_array($result_area)): ?> <option><?php echo $row_a['area'] ?></option> <?php endwhile;?> </select> <select id="second-choice" style="border-radius: 0; width: 100%" class="form-control" name="category"> <option value="">-select-</option> </select> <select id="third-choice" style="border-radius: 0; width: 100%" class="form-control" name="product"> <option value="">-select-</option> </select>
and have following jquery code:
$(document.body).on('change','#first-choice',function(){ //alert('change happened'); $("#second-choice").load("../config/select_eng.php?choice=" + $("#first-choice").val()); }); $(document.body).on('change','#second-choice',function(){ //alert('change happened'); $("#third-choice").load("../config/select_eng_2.php?choice=" + $("#second-choice").val()); });
the thing works once, first select box second not second third. why this? please help.
the php code first one:
$choice = $_get['choice']; $query = "select distinct category archivo area='$choice' , base = 'engineering'"; $result = mysqli_query($connection, $query); while ($row = mysqli_fetch_array($result)) { echo "<option >" . $row{'category'} . "</option>";
the php code second:
$choice = $_get['choice']; $query = "select distinct platform_type archivo category='$choice'"; $result = mysqli_query($connection, $query); while ($row = mysqli_fetch_array($result)) { echo "<option value='{$row['platform_type']}'>" . $row{'platform_type'} . "</option>";
}
you need exact copy of second in select_eng.php.
<select id="second-choice" style="border-radius: 0; width: 100%" class="form-control" name="category" id="area"> <option value="">-select-</option> //select option populated db </select>
and can put second select around span id:
//use code in main page. <span id="third-choice"> <select id="second-choice" style="border-radius: 0; width: 100%" class="form-control" name="category"> <option value="">-select-</option> </select> </span> //in select_eng.php, use $choice = $_get['choice']; $query = "select distinct platform_type archivo category='$choice'"; $result = mysqli_query($connection, $query); echo '<select id="second-choice" style="border-radius: 0; width: 100%" class="form-control" name="category">'; while ($row = mysqli_fetch_array($result)) { echo '<option value="'.$row['platform_type'].'">'.$row['platform_type'] .'</option>'; } echo '</select>';
id selector must unique. have 2 ids in select. not need
id="area"` @ all. hope may help.
Comments
Post a Comment