![]() |
fill select (drop down) element dynamically
Hello everyone!
I have a select (combo box) element that gets filled with items when selected item changed in another one (master combo box). It works in Chrome, FireFox but not in IE (all latest browser versions). How do I populate the items in the child combo box: - ajax call of a PHP script - that returns items for the combo box: echo '<option value="' . $id . '">' . $name . '</option>'; - setting innerHTML attribute of the child combo box to a value that gets returned by the ajax call: document.forms['parametersForm'].elements['stationId'].innerHTML = html; Do I need to return JSON object (or XML) by the PHP script and programically add items (in JavaScript) in the ajax callback or is there an alternative? Obviously building DOM with echoing PHP result doesn't work well in IE. Thanks for your future help! Regards |
It should work just fine in IE if it's coded right.
Maybe if you showed the code you are using now???? FWIW, for a simple list of <option>s you probably don't need to use JSON. Just returning a list of string values would surely work fine. But there's also no reason JSON shouldn't work. |
Hi,
the problem is that the innerHTML attribute of a select element cannot be set in IE. It does not cause an error, but it does not work. The following example does not work in IE, but it works in Firefox, Chrome, Safari and Opera: Code:
<head>Code:
<head>Option object, options collection. |
I did exactly as gumape said. But I returned JSON from PHP. So the PHP constructs 2D array, encodes to JSON (json_encode() function), returns it, JavaScript gets the response with ajax, evals it (eval() function) and processes as gumape said. Cause setting innerHTML attribute in IE really doesn't work.
If someone wants to know more about that, I can provide additional info. |
Yep, would have suggested doing exactly that if I'd read the original post more carefully where you said you were trying to use innerHTML. The 2D array from JSON is better suited for creating Option elements, anyway, rather than using innerHTML.
|
| All times are GMT +1. The time now is 05:50 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.