Add the ability to search xml tags by either first or last name using Javascript
<p>How do I add the ability to search xml tags by either first or last name using Javascript? At the moment it only works for first name. See code.</p>

<pre><code>&lt;html&gt;

&lt;head&gt;
&lt;script type="text/javascript"&gt;

function createRequestObject() {
var ro
var browser = navigator.appName
if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP")
}else{
    ro = new XMLHttpRequest()
}
return ro
}

var http = createRequestObject()

function sndReq() {

http.open('get', 'js2lab5.xml', true)
http.onreadystatechange = handleResponse
http.send(null)
 }

function handleResponse() {

if(http.readyState == 4){

    var response = http.responseXML.documentElement
</code></pre>

<p>listings=response.getElementsByTagName("LISTING")</p>

<p>for (i=0;i

<pre><code>if (nameobj[0].firstChild.data == document.getElementById("first").value){

    addressobj = listings[i].getElementsByTagName("ADDRESS")
    phoneobj = listings[i].getElementsByTagName("PHONE")
           imgobj = listings[i].getElementsByTagName("IMAGE")


           document.getElementById("address").innerHTML = addressobj[0].firstChild.data
           document.getElementById("phone").innerHTML = phoneobj[0].firstChild.data
           document.getElementById("photo").innerHTML = "&lt;img src=' " + imgobj[0].firstChild.data + " ' /&gt;"


          }
     }
  }
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="search"&gt;
  &lt;input type="text" id="first" /&gt;
  &lt;input type="button" value="Search Phonebook" onClick="sndReq()" /&gt;
&lt;/form&gt;
  &lt;div id="address"&gt;&lt;/div&gt;
  &lt;div id="phone"&gt;&lt;/div&gt;
  &lt;div id="photo"&gt;&lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>And the XML code:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE PHONEBOOK&gt;
&lt;PHONEBOOK&gt;
   &lt;LISTING&gt;
      &lt;FIRST&gt;John&lt;/FIRST&gt;
      &lt;LAST&gt;Smith&lt;/LAST&gt;
      &lt;PHONE&gt;1-800-123-4567&lt;/PHONE&gt;
      &lt;ADDRESS&gt;320 E. John St, Champaign IL 61820&lt;/ADDRESS&gt;
      &lt;IMAGE&gt;smith.jpg&lt;/IMAGE&gt;
   &lt;/LISTING&gt;
&lt;/PHONEBOOK&gt;
</code></pre>
