title: window.XMLHttpRequest combine with script .change
body: <p>I have a problem with combinning two scripts.
  Fisrt script is working perfectly and taking stuf from mysql:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   function showUser(str)
          {
          if (str=="")
            {
            document.getElementById("txtHint").innerHTML="";
            return;
            } 
          if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
          else
            {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          xmlhttp.onreadystatechange=function()
            {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
              {
              document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
              }
            }
          xmlhttp.open('GET','includes/test-search.php?q='+str,true);
          xmlhttp.send();
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>The second one is working perfectly and it's simple script for inserting data after change:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $("document").ready(function(){
          $("#selection").change(function () {
          $("#someDivName").html( $("#selection option:selected").val() );
      });
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>now the hole point is to combine them.</p>
  
  <p>It's look like, when I load the site it don't have id selection and second script stops but after taking data from php and mysql file test-search.php the missing id selection is on site but the first script is not checking if id selection apear and don't work.</p>
  
  <p>The php code:</p>
  
  <pre><code>&lt;?php
  $q=$_GET["q"];
  $con = mysql_connect('localhost', 'root', '');
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  mysql_select_db("table", $con);
  $sql="SELECT * FROM prod_models WHERE prod_main_group_id = '".$q."'";
  $result = mysql_query($sql);
  echo '
  &lt;select id="selection" name="prod_main_group_id" onchange="change_val()"&gt;
  &lt;option value=""&gt;Wybierz produkt&lt;/option&gt;
  ';
  while($row = mysql_fetch_array($result))
    {
    echo '&lt;option value="'.$row['id'].'"&gt;';
    echo $row['product_name'] . "&lt;/option&gt;";
    }
  echo "&lt;/select&gt;
  ";
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>Code to display changed script:</p>
  
  <pre><code>&lt;input type="text" id="someDivName" value="" /&gt;
  </code></pre>
  
  <p>if any one can help with solving the problem will be realy nice.
  Thx i'm waiting for it now and trying to solve this for my self but now I don't have other ideas for it.</p>