If you have a large table and you are going to be doing this a lot, I would suggest using HTML5 data attributes to link the button with the input field:
<tr>
<td>
<input id="input-1" type=\"number\" name=\"name1\">
</td>
<td>
<button data-input=\"#input-1\"type=\"button\" class=\"button\">Button</button>
</td>
</tr>
<tr>
Notice the id attribute on the input matches the data-input attribute on the button. Now you can do something like this:
$('button').on('click', function() {
var input = $(this).data('input');
var value = $(input).val();
// Do something with the value
});
Update
If the relationship is not one-to-one, you would have to modify the structure a bit. You couldn't use the id attribute, since id's must be unique. Instead, you could give each input a data attribute, such as:
<input data-group="1" type=\"number\" name=\"name1\">
And your button would have a corresponding data attribute:
<button data-input=\"1\"type=\"button\" class=\"button\">Button</button>
Then in your click handler, you could do this:
$('button').on('click', function() {
var input_group = $(this).data('input');
var inputs = $('input[data-group="' + input_group + '"]');
var values = [];
// Read the values into an array
$.each(inputs, function(i, input) {
values.push(input.val());
});
// Do something with the values...
});