javascript - Calculate the sum of products using a td attribute -



javascript - Calculate the sum of products using a td attribute -

i have table :

<table> <thead> <tr> <th>quantity</th> <th>&nbsp;</th> <th>price</th> <th>sum</th> </tr></thead> <tbody> <tr class="sum"> <td><input class="qty" type="text" value="1" /></td> <td>german format: </td> <td data_price="1375.5">1.375,50 &euro;</td> <td></td> </tr> <tr class="sum"> <td><input class="qty" type="text" value="1" /></td> <td>english format:</td> <td data_price="1375.5">&euro;1,375.50</td> <td></td> </tr> <tr class="sum"> <td><input name="text" type="text" class="qty" value="1" /></td> <td>french format:</td> <td data_price="1375.5">1 375,50 &euro;</td> <td></td> </tr> <tr class="sum"> <td><input name="text2" type="text" class="qty" value="1" /></td> <td>italian format:</td> <td data_price="1375.5">&euro;1,375.50</td> <td></td> </tr> <tr class="sum"> <td><input class="qty" type="text" value="1" /></td> <td>spanish format:</td> <td data_price="1375.5">&euro; 1.375,50</td> <td></td> </tr> <tr> <td colspan="3">total</td> <td id="total"></td> </tr> </tbody> </table>

and want utilize value of attribute "data_price" calculate sum in link : http://jsfiddle.net/qmtnz/77/

i want utilize attribute "data_price" in calculation , not .

please help, i'm still beginner in jquery :)

for cost cells, should utilize format:

<td data-price="1375.5">&euro;1,375.50</td>

i.e. hyphen, not underscore

you can use:

$('td').data('price')

to access value - see http://api.jquery.com/data

e.g.

var sum = 0; $('.sum').each(function() { var q = parsefloat($(this).find('.qty').val()); var p = parsefloat($(this).find('td').eq(2).data('price')); sum += q * p; }); $('#total').text(sum);

working demo @ http://jsfiddle.net/alnitak/gzyhn/

javascript jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -