Q:

jQuery find td by attr and set input to variable

 <tr>
    <td></td>
    <td></td>
    <td data-unit="spear" class="tooltip">
        <input type="text" size="2" name="spear" />
    </td>
    <td data-unit="sword" class="tooltip">
        <input type="text" size="2" name="sword" />
    </td>
    <td data-unit="axe" class="tooltip">
        <input type="text" size="2" name="axe" />
    </td>
    <td data-unit="spy" class="tooltip">
        <input type="text" size="2" name="spy" />
    </td>
    <td data-unit="light" class="tooltip">
        <input type="text" size="2" name="light" />
    </td>
    <td data-unit="heavy" class="tooltip">
        <input type="text" size="2" name="heavy" />
    </td>
    <td data-unit="ram" class="tooltip">
        <input type="text" size="2" name="ram" />
    </td>
    <td data-unit="catapult" class="tooltip">
        <input type="text" size="2" name="catapult" />
    </td>
    <td>
        <input type="button" value="Aanvragen" class="btn call_button" data-village="21603" />
    </td>
</tr>

I first activated every tr that fullfilled a certain condition and set the input to 0:
var everytr = $('#village_troup_list tbody tr:has(input[value="Aanvragen"])')
everytr.find('input[type="text"]').val(0);

For each of these trs, I now want to set every td with data-unit="spear", each td with data-unit="sword", etc to my variable.
var numberofspear = 10;
var numberofsword = 15;

I tried:
$('#village_troup_list tbody td[data-unit="spear"]').find('input[type="text"]').val(numberofspear);

And some other things, but they all don't work. :( Does anyone know how I could do this?
I'll explain it a bit better: I want to set the input to my variable for each td with attr data-unit="spear" (data-unit="myunitx".)

A:

Try this,
$('#village_troup_list').find('input[value="Aanvragen"]').val(numberofspear);

Demo
And Your html is not looking well you should close your tds like,
<table id="village_troup_list">
    <tr>
        <td></td>
        <td data-unit="spear" class="tooltip">
            <input type="text" size="2" name="spear" />
        </td>
        <td data-unit="sword" class="tooltip">
            <input type="text" size="2" name="sword" />
        </td>
        <td data-unit="axe" class="tooltip"></td>
        <td data-unit="spy" class="tooltip">
            <input type="text" size="2" name="spy" />
        </td>
        <td data-unit="light" class="tooltip"></td>
        <td data-unit="heavy" class="tooltip"></td>
        <td data-unit="ram" class="tooltip"></td>
        <td data-unit="catapult" class="tooltip"></td>
        <td>
            <input type="button" value="Aanvragen" class="btn call_button" data-village="9598" />
        </td>
    </tr>
</table>

Updated Demo
You can set value of button by using its class name like
$('#village_troup_list').find('input.call_button').val(numberofspear);

Class Demo
Updated, to set the numberofspear to spear inputs try to use [name=selector],
$('#village_troup_list').find('input[name=spear]').val(numberofspear);

Spear Demo

