title: Eliminating repetition in similar scripts
body: <p>I have a series of webpages with prices that change rapidly and due to a certain constraint, I need all the pages to query a certain XML file that is dynamically updated.  </p>
  
  <p>This is what I have cobbled together, and though it works fine, I'm sure I'm overdoing it and adding a full script for every price line is clunky at best.</p>
  
  <pre><code>&lt;h4&gt; &lt;script&gt;
  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","flightprice.xml",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 
  var x=xmlDoc.getElementsByTagName("CD");
  for (i=0;i&lt;x.length;i++)
    { 
    document.write(x[i].getElementsByTagName("EACH2PAX1")[0].childNodes[0].nodeValue);
    document.write(" per person / Duration: 30 minutes, 2 passenger minimum. ");
    } 
  &lt;/script&gt;&lt;/h4&gt;
  
  
  &lt;h4&gt; &lt;script&gt;
  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","flightprice.xml",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 
  var x=xmlDoc.getElementsByTagName("CD");
  for (i=0;i&lt;x.length;i++)
    { 
    document.write(x[i].getElementsByTagName("EACH3PAX1")[0].childNodes[0].nodeValue);
    document.write(" per person with passengers");
    } 
  &lt;/script&gt;&lt;/h4&gt;
  </code></pre>
  
  <p>Since each script is a IDENTICAL, except for the document.write value in each, I was hoping for a cleaner way of doing this. </p>
  
  <p>Please excuse my ignorance... I'm 13 years old and trying to learn with the tools available to me.  </p>
  
  <p>thank you</p>