title: error filling in testfield using mysql and php javascript ajax
body: <p>slightly varied question but I have a script that runs and gets data from a mysql db. The end result shows them as buttons, when i click the buttons it gives me an alert with the correct id number correspsonding to whats selected, but when i try to put that into a textfield is isnt the same, its basically the last in the mysql? WHy would the alert show the correct and the updated textfield so totally different information??</p>
  
  <p>The working php that alerts the correct info is :</p>
  
  <pre><code>    &lt;?php
  
   include('config.php');
  
   $action = $_REQUEST['action'];
  
   if($action=="showAll"){
  
    $stmt=$dbcon-&gt;prepare('SELECT product_id, product_name FROM products ORDER BY product_name');
    $stmt-&gt;execute();
  
   }else{
  
    $stmt=$dbcon-&gt;prepare('SELECT product_id, product_name FROM products WHERE cat_id=:cid ORDER BY product_name');
    $stmt-&gt;execute(array(':cid'=&gt;$action));
   }
  
   ?&gt;
   &lt;div class="row"&gt;
   &lt;?php
   if($stmt-&gt;rowCount() &gt; 0){
  
    while($row=$stmt-&gt;fetch(PDO::FETCH_ASSOC))
    {
     extract($row);
  
     ?&gt;
     &lt;div class="col-xs-3"&gt;
     &lt;div style="border-radius:3px; border:#cdcdcd solid 1px; padding:22px;"&gt;&lt;button type="button" class="btn btn-default" onclick="alert('&lt;? echo $product_id; ?&gt;')"&gt;&lt;?php echo $product_name; ?&gt;&lt;/button&gt;&lt;/div&gt;&lt;br /&gt;
     &lt;/div&gt;
     &lt;?php  
    }
  
   }else{
  
    ?&gt;
          &lt;div class="col-xs-3"&gt;
     &lt;div style="border-radius:3px; border:#cdcdcd solid 1px; padding:22px;"&gt;&lt;button type="button" class="btn btn-default" onclick="alert('&lt;? echo $product_id; ?&gt;')"&gt;&lt;?php echo $product_name; ?&gt;&lt;/button&gt;&lt;/div&gt;&lt;br /&gt;
    &lt;/div&gt;
          &lt;?php  
   }
  
  
   ?&gt;
   &lt;/div&gt;
  
   &lt;div&gt;
   text : &lt;input id="textField1" type="text" value="0" align="right" size="13"/&gt;&lt;br&gt;
   &lt;/div&gt;
  
   &lt;script&gt;
  function display()
      {
          document.getElementById("textField1").value = "&lt;? echo $product_name; ?&gt;";
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>But if change the button to use the 'display script' it just shows last in database?</p>
  
  <p></p>