Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    retrieve data from xml using javascript

    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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);
    doc.load('theuritothexmlfile.xml');

    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() });
    doc.load('theuritothexmlfile.xml');

    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/de...ttprequest.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())


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •