Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following is what I used to fix the issues I was having. One problem I was having is testing this locally. It will not work. This also is pending a message if no contact is found. I will update when I find the solution.</p> <p>UPDATE: Solution found. See updated code below:</p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt; function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(); return xhttp.responseXML; } function searchXML() { xmlDoc=loadXMLDoc("Contact.xml"); x=xmlDoc.getElementsByTagName("firstname"); input = document.getElementById("input").value; size = input.length; if (input == null || input == "") { document.getElementById("results").innerHTML= "Please enter a character or name!"; return false; } for (i=0;i&lt;x.length;i++) { startString = firstname.substring(0,size); if (startString.toLowerCase() == input.toLowerCase()) { firstname=xmlDoc.getElementsByTagName("firstname")[i].childNodes[0].nodeValue; lastname=xmlDoc.getElementsByTagName("lastname")[i].childNodes[0].nodeValue; phone=xmlDoc.getElementsByTagName("phone")[i].childNodes[0].nodeValue; street=xmlDoc.getElementsByTagName("street")[i].childNodes[0].nodeValue; city=xmlDoc.getElementsByTagName("city")[i].childNodes[0].nodeValue; state=xmlDoc.getElementsByTagName("state")[i].childNodes[0].nodeValue; postcode=xmlDoc.getElementsByTagName("postcode")[i].childNodes[0].nodeValue; divText = "&lt;h1&gt;The contact details are:&lt;/h1&gt;&lt;br /&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;First Name&lt;/th&gt;&lt;th&gt;Last Name&lt;/th&gt;&lt;th&gt;Phone&lt;/th&gt;&lt;th&gt;Street&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;Postcode&lt;/th&gt;&lt;/tr&gt;" + "&lt;tr&gt;&lt;td&gt;" + firstname + "&lt;/td&gt;&lt;td&gt;" + lastname + "&lt;/td&gt;&lt;td&gt;" + phone + "&lt;/td&gt;&lt;td&gt;" + street + "&lt;/td&gt;&lt;td&gt;" + city + "&lt;/td&gt;&lt;td&gt;" + state + "&lt;/td&gt;&lt;td&gt;" + postcode + "&lt;/td&gt;&lt;/tr&gt;" + "&lt;/table&gt;"; break; } else { divText = "&lt;h2&gt;The contact does not exist.&lt;/h2&gt;"; } } document.getElementById("results").innerHTML= divText; } &lt;/script&gt; </code></pre> <p>My html body:</p> <pre><code>&lt;body&gt; First Name: &lt;input type="text" name="firstname" id="input"&gt; &lt;br /&gt; &lt;input type="submit" value="Submit" onClick="searchXML()"&gt; &lt;br /&gt; &lt;br /&gt; &lt;div id="results"&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>I hope this can help someone else out.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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