I have two Joomla list fields (drop-down fields). The the second list field is depending on the value of the first list field.
Now I've tried to change the values of the second form field via jQuery on runtime. But this methode fails, because the value can be seen by the browser inspector, but it wont be shown in the form field (seems that Joomla has its own method to display option fields).
I've tried:
$document->addScriptDeclaration('
jQuery(document).ready(function () {
jQuery("#jform_country").change(function(){
country_id = jQuery("#" + this.id).val(); // this is the first list field
select = document.getElementById("#jform_state");
if (country_id == "Germany") {
// Option 1 will be shown, but only in the inspector
jQuery("#jform_state").append("<option value=Bavaria>Bavaria</option>");
// Option 2 nothing happens
var option = document.createElement("option");
option.text = "Bavaria";
option.value = "Bavaria";
select.appendChild(option);
}
})
});
');
Is there a possibility to fill the list field on runtime resp. to change the values?