This is my tablestructure.
<table>
<tr>
<td>
<input type="text"> 1 </input>
</td>
</tr>
<tr>
<td>
<input type="text"> 1 </input>
</td>
</tr>
<tr>
<td>
<div class="sum"> </div>
</td>
</tr>
I have a onblure event on the input field
( $("input[type=\"text\"]").blur(function()...)
Now I want get both values of the inputfields if one of them gives the blur event. Add those values and post them to the sum div. Any idea?
You probably want to add some
classand/oridattributes to your inputs so that this code will play nicely if dropped into a larger HTML context. However, to answer the question as given:If you’re entering numbers with a decimal point, you’ll probably want to use
parseFloatrather thanparseInt.UPDATE: If your structures are all like the one posted, the easiest way to relate them to one another would be to use an
idattribute on the containing table, and the descendant selector syntax. Then the code would look like this:UPDATE AGAIN: Okay, so you have no way to assign ids to your tables. That’s okay, we can still get this done. You’ll have to use jQuery’s traversal functions
parent()andfind()instead of simple selectors, that’s all.