|
-
September 26th, 2007, 09:18 AM
#7
Re: populating Drop down with items frmo server.
You don't have to parse any XML, you can just output a comma-delimited text like I first wrote. The thing about XML was more informational (because that was the original intention of AJAX, and what it stands for.) So for the sake of simplicity, output a comma-delimited list from PHP and parse it using split() like me and PeejAvery showed in our code examples.
If you really must know, here's how you could do it with an XML output:
Code:
// Variable 'response' is an XmlHttpRequest object that has just finished a request.
var items = response.responseXML.documentElement;
for (var i = 0; i < items.childNodes.length; i++) {
var text = items.childNodes[i].nodeValue;
select.options[i] = new Option(text, text);
}
Note that the above code has not been tested, I'm just assuming the browser handles DOM properly, in which case the above code would work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|