View Full Version : retrieve data from xml using javascript

07-03-2002, 08:03 AM
i'm planning to create two pulldown menus. the first pulldown menu will display car makes such as toyota, ford, etc. this data is retrieved from an xml file. at this stage, the second pulldown menu will remain empty. when a person select toyota from the first pulldown menu, the second pulldown menu will automatically display the toyota models such as camry, corolla, prado, etc. this feature has to be dynamic. if the xml file is updated with a new toyota model, for eg, altis, then the second pulldown menu will be able to display the model altis as well.

how could i do this? could anyone at least suggest some sites which could help me figure out how to create this feature?

Thank you very much for your time and help.

07-03-2002, 03:11 PM
Using the W3C DOM2 Core Recommendation createDocument method and the W3C DOM3 Load And Save Working Draft load method:

var doc = document.implementation.createDocument('','',null);
doc.addEventListener('load', someEventListener, false);

And when the xml file is loaded, someEventListener(event) is fired.

This is for Gecko-only at the moment (NS6, NS7, Mozilla, Beonex, K-meleon, Galeon, etc).

IE supports its own, proprietary way with a well-publicized ActiveX object:

var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.attachEvent('onreadystatechange', function() { if (event.target.readyState == 4) someEventListener() });

Also, both browsers implement a proprietary XMLHttpRequest object:

// in IE:
var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');

// in Gecko:
var xmlhttp = new XMLHttpRequest();

And once the object is defined, they both function
accordingly to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp
In Gecko, all methods start with a lowercase letter, and some properties aren't implemented (i.e. use xmlhttp.send() and not xmlhttp.Send())