I'm experiencing trouble with 2 level dependent dropdown.
When I select 1st dropdown, i have a PARSERERROR alert and second dropdown is not pouplated
Please, any advice about what's wrong?
Here is my code:
HTML
<div class="form-group">
<label>CLASSIFICATION<span class="text-danger">*</span></label>
<select name="document_classification" id="document_classification" class="select-search" data-placeholder="">
<?php
$sql = "SELECT * FROM rm_document_classification_id";
$result = $mysqli->query($sql);
while($row = $result->fetch_assoc()){
echo "<option></option>";
echo "<option value='".$row['classification_id']."'>".$row['classification_description']."</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>SUBJECTS<span class="text-danger">*</span></label>
<select name="document_subject" class="form-control" style="width:350px">
</select>
</div>
SCRIPT
$( "select[name='document_classification']" ).change(function () {
var class_id = $(this).val();
//alert(class_id);
if(class_id) {
$.ajax({
url: "ajax.php",
type: "GET",
dataType: 'json',
data: {'classification_id':class_id},
success: function(data) {
$('select[name="document_subject"]').empty();
$.each(data, function(key, value) {
$('select[name="document_subject"]').append('<option value="'+ key +'">'+ value +'</option>');
});
},
error: function (request,status, error) {
console.log(error);
alert(status);
}
});
}else{
$('select[name="document_subject"]').empty();
}
});
PHP
<?
include_once "../config.php";
$sql = "SELECT * FROM rm_document_subject_id
WHERE subject_classification_id LIKE '%".$_GET['classification_id']."%'";
$result = $mysqli->query($sql);
$json = [];
while($row = $result->fetch_assoc()){
$json[$row['subject_id']] = $row['subject_description'];
}
echo json_encode($json);
?>
Thanks all. HID Thanks all. HID Thanks all. HID