title: How to make search result clickable as if clicking a button
body: <p>I have a html page with a form and input fields. When a user enters text into the input field, at each key a database is searched for corresponding values. This is done through a Javascript call which then does an XMLHttpRequest to a PHP script. In the PHP I return a top 10 list of matches. This list is then shown on the html page. </p>
  
  <p>What I now would like is to make each item in the list clickable and when clicked it should fill the form field with the value. I can make the results linkable by adding <code>&lt;a href&gt;</code>  around them, but the onClick doesn't seem to work for it.</p>
  
  <p>Html/PHP page with form:</p>
  
  <pre><code>&lt;form action="index.php?page=n0402" method="post" Name="AddPolish" &gt;
      &lt;div id="frmBrandInput"&gt;
          &lt;label for="frmBrand"&gt;Brand name:&lt;/label&gt;
          &lt;input type="text" name="frmBrand" size="50" onkeyup="n0401CheckRecords(1);" onchange="n0401AddResults_Clear();" maxlength="100" id="frmBrand"   /&gt;
      &lt;/div&gt;
      &lt;div id="ListResults"&gt;
          &lt;ul style="list-style-type:none;"&gt;
              &lt;div class="n0401AddResults" id="n0401AddResults_Status"&gt;
              &lt;/div&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  
      &lt;button type="submit" name="submit" value="submit-value"&gt;ADD&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The javascript calls the PHP and changes the n0401AddResults_Status:</p>
  
  <pre><code>function n0401CheckRecords( jsCheck){
  ---- xmlhttp request code and return snipped out --- 
  document.getElementById("n0401AddResults_Status").innerHTML = return_data;
  }
  </code></pre>
  
  <p>The PHP page that checks the database:</p>
  
  <pre><code>While ($dbCheck_result = mysqli_fetch_row($result))
  {
  echo "&lt;li class='CheckListItem' onClick='ClickMe();'&gt;&lt;a href='".$dbCheck_result[1]."'&gt;".$dbCheck_result[1] ."&lt;/a&gt;&lt;/li&gt;";
  }
  </code></pre>
  
  <p>What is the best way to structure that return string to make it clickable? Btw, I'm now using a list for it, but that is not a requirement to me.</p>
  
  <p>Btw I'm NOT using JQuery.</p>