HI freinds I developing a Simple calculator in which when user selects any product by check the checkbox then the price of the selected product will be displayed in .count <td>there are four product and each product has its own checkhox and .count class.
Now the main thing I want when user select any of product and increase its quantity then plus all the amount and display in .countTotal.
As per my code its showing NaN
Please help me
You can se my code below or you can also check fiddle here
HTML
<div class="brochure"><table width="100%" border="0" cellspacing="0" cellpadding="10" >
<tr>
<td width="21%" align="center"><input type="checkbox" value="50" class="" name="radio">
Rs. 50 </td>
<td width="29%" align="center"><img src="images/thumb_brochure_singlepage_back.jpg" alt=" "></td>
<td width="10%" align="center"><label for=" "></label>
<input name=" 2" type="text" class="qty" id=" " maxlength="2"></td>
<td width="40%" align="center" class="count"> </td>
</tr>
<tr>
<td align="center"><input type="checkbox" value="75" class="" name="radio5">
Rs. 75 </td>
<td align="center"><img src="images/thumb_brochure_singlepage_front.jpg" width="50" height="117" alt=" "></td>
<td align="center"><input name=" 3" type="text" class="qty" id=" 2" maxlength="2"></td>
<td align="center" class="count"> </td>
</tr>
<tr>
<td align="center"><input type="checkbox" value="100" class="" name="radio6">
Rs. 100 </td>
<td align="center"><img src="images/thumb_brochure_singlepage_front.jpg" width="50" height="117" alt=" "></td>
<td align="center"><input name=" 4" type="text" class="qty" id=" 3" maxlength="2"></td>
<td align="center" class="count"> </td>
</tr>
<tr>
<td align="center"><input type="checkbox" value="125" class="" name="radio7">
Rs. 125 </td>
<td align="center"><img src="images/thumb_brochure_singlepage_back.jpg" alt=" "></td>
<td align="center"><input name=" 6" type="text" class="qty" id=" 4" maxlength="2"></td>
<td align="center" class="count"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center">Total</td>
<td align="center" class="countTotal"> </td>
</tr>
</table>
</div>
SCIRPT
$('.sticker input.qty, .brochure input.qty').prop('disabled', true);
var total;
var price = 0;
var qty;
var prPrice = 0;
var i = 0;
var prPricemain = 0;
$('.sticker input[type="checkbox"], .brochure input[type="checkbox"]').on('change',function(){
if($(this).is(':checked'))
{
var val = $(this).attr('value');
$(this).closest('tr').find('input.qty').prop('disabled', false);
$(this).closest('tr').find('input.qty').val('1');
$(this).closest('tr').find('.count').text(val);
$(this).closest('tr').find('input.qty').on('keyup',function(){
qty = $(this).val();
prPrice = qty * val;
$(this).closest('tr').find('.count').text(prPrice);
})
}
else
{
$(this).closest('tr').find('input.qty').prop('disabled', true);
$(this).closest('tr').find('input.qty').val('');
$(this).closest('tr').find('.count').text('');
}
$(this).closest('table').find('.count').each(function() {
prPricemain = parseInt($(this).html());
prPricemain = prPricemain + prPrice
});
$(this).closest('table').find('.countTotal').text(prPricemain);
})
$('.qty').keyup(function(e)
{
if (/\D/g.test(this.value))
{
alert('Numbers Only')
this.value = this.value.replace(/\D/g, '');
}
});