// — Retrieve the list of categories —————————————–
$sql = “SELECT _CATEGORY, _SUBCATEGORY FROM categories WHERE _DEPT = ‘$dept'”;
$db = new MysqliDb(‘CES’);
$selectStatus = $db->rawQuery($sql); /
if ($selectStatus > 0) {
foreach ($selectStatus as $row) {
$categoryArray[] = $row[‘_CATEGORY’];
$subcategoryArray[] = $row[‘_SUBCATEGORY’];
}
}

$(document).ready( function () {
var subcategoryArray = <?php echo ‘[“‘ . implode(‘”, “‘, $subcategoryArray) . ‘”]’ ?>;
On select
$(‘#_CATEGORY_LIST0’).on(‘select2:select’, function (e) {
$(‘#SUB_CATEGORY_LIST0’).val(subcategoryArray[e.params.data.id]);
});
You must be logged in to post a comment.