-1

I want to find a value that has been entered in a text field from a table, and then prepend a name that is on the row of that code.

$('#InputCode').blur(function(){
$('#Table tr').find(this).val()
('.NameCell').append('#NameResult')
})

Here the edit:

<table id="Table1" width="306" border="1">
  <tr>
    <th scope="col">Zip</th>
    <th scope="col" class="Names">Names</th>
    </tr>
  <tr>
    <td>0871</td>
    <td>Dan</td>
    </tr>
  <tr>
    <td>0877</td>
    <td>Dan</td>
    </tr>
  <tr>
    <td>0771</td>
    <td>Bonn</td>
    </tr>
  <tr>
    <td>0772</td>
    <td>Conblentz</td>
    </tr>
</table>

<input name="" type="text" id="InputCode">
<div id="NameResult">
</div>

When a user enter a code into an input field, a name matching the code must be appended/prepended into a div, taken from a table

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Blessing Thinker
  • 261
  • 1
  • 4
  • 14

1 Answers1

0

try out this fiddle

JS Code

$('#InputCode').blur(function () {
    var input = $(this).val();
    $t = $('td').filter(function () {
        return $(this).text() == input
    });
    var res = $t.next().text();
    $('#NameResult').append(res)
})
Siddhartha Gupta
  • 1,140
  • 8
  • 13