Help Please - Coding in Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newbie123
    New Member
    • Nov 2006
    • 1

    #1

    Help Please - Coding in Javascript

    Hi

    I'm having trouble with my javascript. I retrieving my data from a XML document:

    Code:
    <root>
           <item>Happy
                   <item filePath="http://www.smile.com">Smile</item>
                   <item filePath="http://www.laugh.com">Laugh</item>
                   <item filePath="http://www.haha.com">Haha</item>
          </item>
          <item>Sad
                  <item filePath="http://www.cry.com">Cry</item>
                  <item filePath="http://www.upset.com">Upset</item>
          </item>
          <item>Angry
                  <item......>....</item>
          </item>
    </root>
    The following is the code I have so far:

    Code:
       function getXMLlinks() 
       { 
          var XMLVal; 
          var itemURL,i; 
          var itemXML; 
          var dropList,nodes; 
          var headNode; 
          var itemNode;         
    
          XMLVal  = new ActiveXObject("Msxml2.XMLHTTP"); 
          itemXML = new ActiveXObject("Microsoft.XMLDOM"); 
          itemURL = 'http://www.emotions.xml'; 
    
          XMLVal.open("POST",itemURL, false,"",""); 
          XMLVal.setRequestHeader("content-type","text/xml"); 
          XMLVal.send(''); 
    
          itemXML.loadXML(XMLVal.responseText); 
    
          var root = itemXML.documentElement; 
          var elem = root.getElementsByTagName("item"); 
          var n = itemXML.documentElement.firstChild; 
    
          var numNodes = elem.length; 
          var writeLinks = ""; 
          for (var i=0; i<numNodes; i++) 
          { 
              var elemvalue = elem.item(i).getAttribute("filePath"); 
              if (elemvalue == "null") 
              { 
                 writeLinks = writeLinks + elem.text + '<br/>'; 
              } 
              else 
              { 
                 writeLinks = writeLinks + '<a href="' + elemvalue + '">' + elem.item(i).text + '</a><br/>' 
              } 
          } 
          linkList.innerHTML = writeLinks; 
            
       }
    What I am trying to do is get the first "item" nodes and display it on a webpage. Then place all the child "item" nodes under the first "item" node. For example, on the webpage: happy, sad and angry will be displayed. But when the user clicks onto "happy" it expands and smile, laugh and haha will be displayed. When the user clicks onto smile it will redirect the user to the "smile" webpage.

    Any help will be much appreciated.

    Thanks!
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    function countryprocess2 ()
    {

    if (http.readyStat e == 4) {
    //alert (http.readyStat e);
    // Split the comma delimited response into an array
    if(http.status= =200)
    {

    //alert (http.status);
    //alert (http.responseT ext);
    //alert (document.getEl ementById("Coun try").value);
    document.getEle mentById("Your_ school").length =0;
    document.getEle mentById("Your_ school").option s[0]=new Option("Select School"," ");

    if(http.respons eText!="No values")
    {

    var clist=http.resp onseText.split( "_");
    for(i=0;i<clist .length;i++)
    {
    var myclist=clist[i].split(",");
    // alert (myclist);
    document.getEle mentById("Your_ school").option s[i+1]=new Option(myclist[1],myclist[0]);
    }
    }
    else
    {
    document.getEle mentById("Your_ school").length =0;
    document.getEle mentById("Your_ school").option s[0]=new Option("Select School"," ");
    }
    }

    }
    }



    this code get the xml content to filter the date

    vssp

    Comment

    Working...