title: Getting value of a <li> tag to TextField
body: <p>I am getting search results from a MySQL table from a string entered in an input text from a HTML page.</p>
  
  <p>Using AJAX, when the user selects one of the result rows the browser is redirected to a PHP file.</p>
  
  <p>What I need is to put the result on another TextField from the same page and not to open another page.</p>
  
  <p>Here is the code that I have now:</p>
  
  <p>PHP part that is sending the needed output results:</p>
  
  <pre><code>/************************************************
      Search Functionality
  ************************************************/
  
  // Define Output HTML Formating
  $html = '';
  
  $html .= '&lt;li class="result" &gt;';
  $html .= '&lt;img src="iconos_especialidades/logo"  width="94" height="94"  /&gt;';
  $html .= '&lt;a target="_blank" href="urlString" &gt;';
  $html .= '   '.'&lt;h3&gt;nameString&lt;/h3&gt;';
  $html .= '&lt;/a&gt;';
  $html .= '&lt;/li&gt;';
  
  // Get Search
  $search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
  $search_string = $tutorial_db-&gt;real_escape_string($search_string);
  
  // Check Length More Than One Character
  if (strlen($search_string) &gt;= 1 &amp;&amp; $search_string !== ' ') {
      // Build Query
      $query = 'SELECT * FROM tb_especialidades WHERE especialidad LIKE "%'.$search_string.'%" OR especialidad LIKE "%'.$search_string.'%" ORDER BY especialidad';
  
      // Do Search
      $result = $tutorial_db-&gt;query($query);
      while($results = $result-&gt;fetch_array()) {
          $result_array[] = $results;
      }
  
      // Check If We Have Results
      if (isset($result_array)) {
          foreach ($result_array as $result) {
  
              // Format Output Strings And Hightlight Matches
              $display_function = preg_replace("/".$search_string."/i", "&lt;b class='highlight'&gt;".$search_string."&lt;/b&gt;", $result['especialidad']);
              $display_name = preg_replace("/".$search_string."/i", "&lt;b class='highlight'&gt;".$search_string."&lt;/b&gt;", $result['especialidad']);
              $display_url = 'opinar_doc_loc.php?id='.$result['id_especialidad'];
  
              if ($result['icono'] == ""){
              $display_logo = "nada.jpg";
              }
              else {
              $display_logo = $result['icono'] ;
              }
  
              // Insert Name
              $output = str_replace('nameString', $display_name, $html);
  
  
  
              // Insert URL
              $output = str_replace('urlString', $display_url, $output);
              // Insert LOGO
              $output = str_replace('logo', $display_logo, $output);
              // Output
              echo($output);
          }
      }else{
  
          // Format No Results Output
          $output = str_replace('urlString', 'javascript:void(0);', $html);
          $output = str_replace('nameString', '&lt;b&gt;No se ha encontrado la especialidad buscada.&lt;/b&gt;', $output);
          $output = str_replace('functionString', 'Sorry :(', $output);
          // Insert LOGO
              $display_logo = "nada.jpg";
              $output = str_replace('logo', $display_logo, $output);
  
          // Output
          echo($output);
      }
  }
  </code></pre>
  
  <p>And here is the JQuery/Ajax Part:</p>
  
  <pre><code>// Start Ready
  $(document).ready(function() {  
  
      // Icon Click Focus
      $('div.icon').click(function(){
          $('input#search').focus();
      });
  
      // Live Search
      // On Search Submit and Get Results
      function search() {
          var query_value = $('input#search').val();
          $('b#search-string').text(query_value);
          if(query_value !== ''){
              $.ajax({
                  type: "POST",
                  url: "php/search.php",
                  data: { query: query_value },
                  cache: false,
                  success: function(html){
                      $("ul#results").html(html);
                  }
              });
          }return false;    
      }
  
      $("input#search").live("keyup", function(e) {
          // Set Timeout
          clearTimeout($.data(this, 'timer'));
  
          // Set Search String
          var search_string = $(this).val();
  
          // Do Search
          if (search_string == '') {
              $("ul#results").fadeOut();
              $('h4#results-text').fadeOut();
          }else{
              $("ul#results").fadeIn();
              $('h4#results-text').fadeIn();
              $(this).data('timer', setTimeout(search, 100));
  
          };
      });
  
  });
  </code></pre>
  
  <p>How could I put the needed value from the database <strong>$result['id_especialidad']</strong> on a TextField from the HTML page?</p>