Note that there are some explanatory texts on larger screens.

plurals
  1. POparse XML file with javascript in variable on click
    primarykey
    data
    text
    <p>I am trying to load a different xml file everytime a link is clicked, based on its href. I have the following in head:</p> <p>JAVASCRIPT</p> <pre><code>window.onload=function() { loadXMLDoc("papers.xml"); // loads the default xml file so that page is not empty } function scanForXML(){ var extLinks=document.getElementById('results_list').getElementsByTagName('a'); for (i=0; i&lt;extLinks.length; i++) { extLinks[i].onclick=function getName() { var fileName=this.getAttribute('href'); loadXMLDoc(fileName); return false; } } } </code></pre> <p>HTML</p> <pre><code>&lt;ol id="results_list"&gt; &lt;li&gt; &lt;a class="tooltip" href="paper2.xml"&gt; Teaching with Tablet PC's &lt;/a&gt;&lt;/li&gt; &lt;li&gt; &lt;a href="paper3.xml" class="tooltip"&gt; Tablet PC’s as Instructional Tools &lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>The onclick event works, I get the href value but the new xmlFile does not get loaded. Any ideas why?</p> <p>ps: no jquery plz, cannot use that. trying to learn better basic javascript</p> <p>The Javascript load code - by the way it does not work in chrome and opera - but works the default xml file gets loaded in safari Code:</p> <pre><code>function loadXMLDoc(dname) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET",dname,false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; } </code></pre> <p>Thanks! K</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload