views:

38

answers:

1

Hello.

Take a look at this table:

<table cellpadding="0" cellspacing="0" class="order_form">
    <tr>
        <th>Amount</th>
        <th>Desc</th>
        <th>Price</th>
        <th>Total</th>
    </tr>
    <tr>
        <td><input type="text" class="order_count" /></td>
        <td>
            <span class="order_desc">Middagstallerken</span>
        </td>
        <td>
            <span class="order_price">1,15</span>
        </td>
        <td>
            <span class="order_each_total"></span>
        </td>
    </tr>
    [...]
</table>

Upon entering amount I need to select the class "order_price" and multiply it with the value of the input "order_count" and place it in "order_each_count". I have a lot of these rows so I need to find the next class in the row.

I have tried using some function like this but without result:

<script type="text/javascript">
    $(document).ready(function(){
        $('.order_count').keyup(function() {
            var each_price = $(this).prevUntil("tr").find("span.order_price").text();
        });
     });
</script>

I hope someone have a good solution :-)

+2  A: 
Tatu Ulmanen
Very good :-) Works like a charm, except the replace function. Its not recognized.
meep
You should pass a radix to parseInt unless you want it to guess one. Eg, parseInt($(this).val(), 10). https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Functions/ParseInt
Douglas
Fixed replace by switching .toFixed and .replace :-)
meep
@meep, yup, my mistake: replace works only on strings, and toFixed creates a string from a number. And @Douglas, you're right also, I've modified my answer.
Tatu Ulmanen