unable to calculate textfield values
Posted
by
user1726508
on Stack Overflow
See other posts from Stack Overflow
or by user1726508
Published on 2012-11-18T10:47:21Z
Indexed on
2012/11/18
10:59 UTC
Read the original article
Hit count: 219
i am trying to change the input field when users changes the quantity of items in a text field. Here i am iterating my list from my database. Now i have to make invoice for customer.
In my code , if i am changing quantity of a single item, then it is effecting all the other items in the list. I want to change only to the specific items,where its quantity has been change.
Below code is giving me error. It is changing all the items value on single change of item quantity.
my code;
<script type="text/javascript">
$(document).ready(function(){
$(function() {
$('input[name="quantity"]').change(function() {
var unitprice = $('input[name^="unitprice"]').val();
$(this).parents('tr').find('input[name^="price"]').val($(this).val() * unitprice);
});
});
});
</script>
<tr>
<td height="65%" valign="top" width="100%">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<s:iterator value="#session.BOK" status="userStatus">
<tr style="height: 10px;">
<td width="65%" align="left"><s:property value="bookTitile"/></td>
<td width="10%" align="left"><s:textfield name="unitprice" value="%{price}" size="4"/></td>
<td width="10%" align="center"><s:textfield name="quantity" value="%{quantity}" size="2"/></td>
<td width="15%" align="center"><s:textfield name="price" size="6"></s:textfield> </td>
</tr>
</s:iterator>
</table>
</td>
</tr>
output looks like this image...
© Stack Overflow or respective owner