jquery - I want to do calculation inbetween column table and the values should be stored in Final Amount column -
kindly me new this. want calculation (selected value divisible 1000) , multiple amount , should stored in 5th column. ie product1 = (100 / 1000) * 100 = 10
here code:
<table border="1"> <tbody> <tr> <td width="334">s.no.</td> <td width="334">product name</td> <td width="334">amount</td> <td width="334">grams/kg</td> <td width="334">final amount</td> </tr> <tr align="center"> <td>1</td> <td>product1</td> <td>100</td> <td> <select id="grams"> <option value=""></option> <option value="100">100g</option> <option value="250">250g</option> <option value="500">500g</option> </select> </td> <td>i want calculation (selectedvalue / 1000) * amount, amount want reflect here</td> </tr> <tr align="center"> <td>2</td> <td>product2</td> <td>200</td> <td> <select id="grams"> <option value=""></option> <option value="100">100g</option> <option value="250">250g</option> <option value="500">500g</option> </select> </td> <td>i want calculation (selectvalue / 1000) * amount, amount want reflect here</td> </tr> </tbody>
this might understand how format table values
$(function(){ $('select').change(function(){ var td_id = 'row'+$(this).attr('id'); var val = $(this).val(); var amount = $('.'+td_id+'-amount').html(); $('#'+td_id).html(val/1000*amount); }); });
in example have add ids
, classes
. see fiddle
(i thought wanted have more 2 rows. other answers may more easy use in case)
Comments
Post a Comment