PHP, JavaScript combo. I have a site with 4 dropdowns. The dropdowns are updated in sequence based on previous dropdown. It works fine when I manually select options, but not when i fill in default values from MySQL records. Codesnip with 2 dropdowns where dropdown 2 is based on dropdown 1 selection, see comments in first three lines:
jQuery('#ClassLevelID').val(data["ClassMin"]); //First dropdown
ClassLevelOnChange(); // Calls DB and gets new values. One value is "4" (i checked that)
jQuery('#CatID').val(4); // Trying to update dropdown 2 to value "4" but nothing happens THIS is what doesn't work properly.
// The #CatID dropdown is filled with values correctly, i see them all. But jQuery does not change from option value 0 to 4 as i want it to.
function ClassLevelOnChange(){
jQuery('#CatID').find('option').remove();
jQuery('#CatID').append('<option value="0">Choose option</option>');
var SelectedClassLevel = document.getElementById("ClassLevelID").value;
jQuery.ajax({
type: 'POST',
url: 'includes/db_GetCategory.php',
data: {"SelectedClassLevel":SelectedClassLevel},
success: function(result){
var result=jQuery.parseJSON(result);
var x = 0;
jQuery.each(result.class_id, function(index, value){
ClassName = result.class_text[x];
jQuery('#CatID').append('<option value="' + value + '">' + ClassName + '</option>');
x = x + 1;
});
}
});
}
I tried some refresh but no results.