I know that I need to use the onChange event from the first element to trigger the AJAX call to query the database and return results, but I'm unclear on how to use PHP and Javascript to create the new options.
I have seen an example before but can't find it again. It involved using (this.value) from the first <select> element to pass a value via AJAX, and use javascript similar to the following to create the new option elements in the second <select> element:
selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);
I also vaguely recall that the eval() function was used... somewhere.
As an example, when I select a country from a drop-down select box, I would like to autopopulate a second select box with relevant states.
The problem is, since I'm getting the option data from the database, and need to return this as interpretable javascript, how is this outputted via the AJAX response variable?
Alternatively, would it be possible to output function calls for a "new option" function?
Any help is appreciated.
I have seen an example before but can't find it again. It involved using (this.value) from the first <select> element to pass a value via AJAX, and use javascript similar to the following to create the new option elements in the second <select> element:
selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);
I also vaguely recall that the eval() function was used... somewhere.
As an example, when I select a country from a drop-down select box, I would like to autopopulate a second select box with relevant states.
The problem is, since I'm getting the option data from the database, and need to return this as interpretable javascript, how is this outputted via the AJAX response variable?
Alternatively, would it be possible to output function calls for a "new option" function?
Any help is appreciated.