title: ajax update qty where id and qty
body: <p>i am trying to update quantity in a cart where there are multiple items, </p>
  
  <p>for example -</p>
  
  <pre><code>var get id of order item
  var get quantity
  post both to updateqty.php
  </code></pre>
  
  <p>with multiple lines on order there are multiple textboxes with the id of qty and multiple hidden inputs with the id of part so it will only work on the first id that it finds on that page, i need it to be able to update other items in the order, </p>
  
  <p>so for example </p>
  
  <pre><code>get class of the textbox, then find out which qty is being updated, then update the quantity of the item.
  </code></pre>
  
  <p>if anyone has an idea how this can be done it would be appreciated.</p>
  
  <pre><code>&lt;script&gt;
  
  
  function updateqty() {
      var ud_first = document.getElementById('part').value;
      var ud_last = document.getElementById('qty').value;
  
      if (window.XMLHttpRequest) {
          xmlhttp = new XMLHttpRequest();
      }
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById("cart").innerHTML = xmlhttp.responseText;
          }
      }
      xmlhttp.open("GET", "php/updateqty.php?order=&lt;?php echo $order; ?&gt;&amp;id=" + ud_first + "&amp;qty="+ud_last, true);
      xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;?php 
  
  
  $sql="SELECT * FROM `orders` WHERE  `invoice` = '".$order."' ORDER BY id DESC";
  
  $result = mysql_query($sql);
  echo"
       &lt;table id='POITable' width='100%' border='1'&gt;
          &lt;tr&gt;
              &lt;td&gt;SKU&lt;/td&gt;
              &lt;td&gt;QTY&lt;/td&gt;
              &lt;td width='45%'&gt;item&lt;/td&gt;
              &lt;td&gt;Unit Price&lt;/td&gt;
              &lt;td&gt;Line Price&lt;/td&gt;
              &lt;td&gt;Delete&lt;/td&gt;
          &lt;/tr&gt;";
  while($row = mysql_fetch_array($result))
    {
  echo"&lt;tr&gt;&lt;td&gt;" . $row['part'] . "&lt;/td&gt;&lt;td&gt;&lt;form name='test'&gt;
     &lt;input type='hidden' value='" . $row[id] . "' id='part'&gt;   &lt;input type='text' id='qty' value='" . $row['qty'] . "' onblur='updateqty(this.id)'&gt;&lt;/form&gt;&lt;/td&gt;&lt;td&gt;" . $row['description'] . "&lt;/td&gt;&lt;td&gt;" . $row['price'] . "&lt;/td&gt;&lt;td&gt;" . $row['lineprice'] . "&lt;/td&gt;&lt;td&gt; &lt;input type='image' src='images/btn_delete.png' value='" . $row[id] . "' onclick='deletesku(this.value)' height='30'/&gt;&lt;/td&gt;
  ";
  
   }
  ?&gt;  
  </code></pre>
  
  <p>the insert php is </p>
  
  <pre><code>$id=$_GET[id];
  
  $sql2="SELECT * FROM  `orders` WHERE  `id` = '".$id."'";
  
  $result2 = mysql_query($sql2);
  
  $row2 = mysql_fetch_array($result2);
  
  $order=$_GET[order];
  $qty=$_GET[qty];
  
  $sql="SELECT * FROM  `stock` WHERE  `part` = '".$part."'";
  
  $result = mysql_query($sql);
  
  $row1 = mysql_fetch_array($result);
  
  $lineprice=$qty * $row2[price];
  
  $sqlins1 = "UPDATE `orders` SET qty='$qty', lineprice='$lineprice' WHERE id = '".$id."'";
  </code></pre>
  
  <p>it is ids in the html that there are multiples of NOT THE MYSQL TABLE </p>
  
  <p>so i need it to pick up the id of a product in the cart and update the quantity of that id by ajax</p>
  
  <p>the impotant bits of the script are</p>
  
  <pre><code>    function updateqty() {
          var ud_first = document.getElementById('part').value;
          var ud_last = document.getElementById('qty').value;
  
          if (window.XMLHttpRequest) {
              xmlhttp = new XMLHttpRequest();
          }
          xmlhttp.onreadystatechange = function () {
              if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
                  document.getElementById("cart").innerHTML = xmlhttp.responseText;
              }
          }
          xmlhttp.open("GET", "php/updateqty.php?order=&lt;?php echo $order; ?&gt;&amp;id=" + ud_first + "&amp;qty="+ud_last, true);
          xmlhttp.send();
      }
      &lt;/script&gt;
      &lt;?php 
  
  
      $sql="SELECT * FROM `orders` WHERE  `invoice` = '".$order."' ORDER BY id DESC";
  
      $result = mysql_query($sql);
      while($row = mysql_fetch_array($result))
        {
      echo"&lt;tr&gt;&lt;td&gt;" . $row['part'] . "&lt;/td&gt;
  
  &lt;td&gt;
  
      &lt;form name='test'&gt;
             &lt;input type='hidden' value='" . $row[id] . "' id='part'&gt;
         &lt;input type='text' id='qty' value='" . $row['qty'] . "' onblur='updateqty(this.id)'&gt;&lt;/form&gt;
  
      &lt;/td&gt;&lt;td&gt;" . $row['description'] . "&lt;/td&gt;&lt;td&gt;" . $row['price'] . "&lt;/td&gt;&lt;td&gt;" . $row['lineprice'] . "&lt;/td&gt;&lt;td&gt; &lt;input type='image' src='images/btn_delete.png' value='" . $row[id] . "' onclick='deletesku(this.value)' height='30'/&gt;&lt;/td&gt;
          ";
  
           }
  </code></pre>
  
  <p>Thanks in advance</p>