Note that there are some explanatory texts on larger screens.

plurals
  1. PORequires double button click - simple Ajax application
    primarykey
    data
    text
    <p>I just started learning AJAX and have made a simple script. Below is the script.</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome to the forum&lt;/title&gt; &lt;script&gt; var XMLHttpRequestObject = false; if(window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); XMLHttpRequestObject.overrideMimeType("text/xml"); } else { document.getElementById("text").innerHTML = "Sorry, your browser does not support AJAX!"; } function getData(dataSource) { XMLHttpRequestObject.open("GET", dataSource); XMLHttpRequestObject.onreadystatechange = function() { if(XMLHttpRequestObject.readyState == 4 &amp;&amp; XMLHttpRequestObject.status == 200) { responseData = XMLHttpRequestObject.responseXML; responseDataList = responseData.getElementsByTagName("os"); } } XMLHttpRequestObject.send(null); } function displayMenuItems(dataSource,selectID) { getData(dataSource); var i; for(i=0; i&lt;responseDataList.length; i++) { document.getElementById(selectID).options[i] = new Option(responseDataList[i].firstChild.data); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;select size="1" id="os"&gt; &lt;option&gt;Select and OS&lt;/option&gt; &lt;/select&gt; &lt;input type="button" value="Display OS list" onclick="displayMenuItems('os.xml','os')" /&gt; &lt;/form&gt; &lt;div id="text"&gt;The Operating System you use will appear here!&lt;/div&gt; &lt;/body&gt; </code></pre> <p></p> <p>When I click the button, what I expect is to show the list of OSes in the HTML list , but it occurs only after clicking the button twice. I can't figure out what the problem is! :(</p> <p>Below is the XML script:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;osList&gt; &lt;os&gt;Ubuntu&lt;/os&gt; &lt;os&gt;Fedora&lt;/os&gt; &lt;os&gt;Windows&lt;/os&gt; &lt;/osList&gt; </code></pre>
    singulars
    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.
    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