title: onclick fill input box with text
body: <p>I have pretty much copied and pasted from <a href="https://stackoverflow.com/questions/9452296/javascript-to-jquery-add-text-in-input-onclick">this Stackoverflow question/answer</a>, and it doesn't seem to want to work on my page. I also tried creating a blank PHP page to try it on, and it still doesn't work.</p>
  
  <p>Also the jQuery library that I included in the header was one off Google's library, and also jQuery's official one: <a href="http://code.jquery.com/jquery-latest.min.js" rel="nofollow noreferrer">http://code.jquery.com/jquery-latest.min.js</a>.</p>
  
  <p>It has to be something with the encoding or something because the code works fine in my browser on JSFiddle also:
  <a href="http://jsfiddle.net/kn3Qu/" rel="nofollow noreferrer">http://jsfiddle.net/kn3Qu/</a><br />
  <br /><br />
  Here is the code I'm using personally:</p>
  
  <pre><code>&lt;input id="dam" type="text" /&gt;
  
  &lt;div id="dam_return"&gt;
      &lt;a href="#"&gt;DLH Victoria&lt;/a&gt;
      &lt;a href="#"&gt;DLH Sam&lt;/a&gt;
      &lt;a href="#"&gt;Studly&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and the Javascript:</p>
  
  <pre><code>$('#dam_return a').click(function() {
      var value = $(this).html();
      var input = $('#dam');
      input.val(value);
      return false;
  });
  </code></pre>
  
  <p>If anyone could help me out that would be awesome!</p>
  
  <p>EDIT: I'm thinking my problem is because of a SQL query that happens everytime a key is pressed on the "dam" input.</p>
  
  <p>Here is the EXACT SQL query that happens:</p>
  
  <pre><code>&lt;div id="dam_return_search"&gt;&lt;a href="#"&gt;Maybe this one works? (but no, it doesn't)&lt;/a&gt;&lt;br /&gt;
  &lt;?php
  
  $connect = // blahblahaa
  
  if (isset($_GET['dam_text'])) {
      getSuggest($text);
  }
  
  function getSuggest($text) {
  
      $dam = $_GET['dam_text'];
  
      $sqlCommand = "SELECT `name` FROM `alpacas1` WHERE `name` LIKE '%$dam%'";
  
      $query = mysql_query($sqlCommand);
  
      $result_count = mysql_num_rows($query);
  
      while ($row = mysql_fetch_assoc($query)) {
          echo '&lt;a href=#&gt;'.$row['name'].'&lt;/a&gt;&lt;br /&gt;';
      }
  
  }
  
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the DAM input box and code associated with it:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function suggest1() {
      var dam_text = document.getElementById('dam').value;
  
      if (window.XMLHttpRequest) {
          xmlhttp = new XMLHttpRequest();
      } else {
          xmlhttp = new ActiveXObject('MicrosoftXMLHTTP');
      }
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById('dam_return').innerHTML = xmlhttp.responseText;
          }
      }
      var target = 'dam_search.php?dam_text=' + dam_text;
      xmlhttp.open('GET', target, true);
      xmlhttp.send();
  }
  &lt;/script&gt;
  
  
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
      $("#dam_return_search a").click(function(){
          var value = $(this).html();
          var input = $('#dam');
          input.val(value);
      });
  });
  &lt;/script&gt;
  
  
  &lt;tr&gt;
    &lt;td id="label"&gt;Dam:&lt;/td&gt; 
    &lt;td id="option"&gt;
      &lt;input type="text" name="dam" id="dam" value="&lt;?php echo "$dam"; ?&gt;" onkeyup="suggest1();"&gt;&lt;br /&gt;
      &lt;div id="dam_return"&gt;&lt;/div&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>