Whatever item in a table is clicked, put that value on a hidden input
<p>I need whatever item clicked on a table to be captured and putted in a hidden input.
This is as far as I got:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var $rows = $('#table tbody tr');
$('#search').keyup(function() {
    var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
        reg = RegExp(val, 'i'),
        text;

    $rows.show().filter(function() {
        text = $(this).text().replace(/\s+/g, ' ');
        return !reg.test(text);
    }).hide();
});
$('td').click(function() {
    var txt = $('td:first-child').text();
    $('#tipo').val(txt);
});
    </code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;div class="input-group"&gt;
    &lt;span class="input-group-addon" id="rotulo"&gt;Filtrar:&lt;/span&gt;
    &lt;input type="text" class="form-control" placeholder="" aria-describedby="rotulo" id="search"&gt;
&lt;/div&gt;
&lt;table class="table" id="table"&gt;
    &lt;tr&gt;
        &lt;td&gt;1st Value&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
        &lt;td&gt;2nd Value &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
        &lt;td&gt;3rd Value &lt;/td&gt;
    &lt;/tr&gt;
   &lt;/table&gt;
&lt;input type="text" id="tipo" value=""&gt;</code></pre>
</div>
</div>
</p>

<p>The problem is, whatever value I click, many items in the table are selected, even when this first item is hidden.
Jquery is being used.</p>