jquery question, how can i make it calc. multi. form with different form IDs? -


jq question again, i've 4 form in 1 page , script calc. total,

how can calc different total amount < form id="#" > things ?

thanks

<script type="text/javascript">      $(document).ready(function() {         var total = 0;         function calctotal() {             $("input:checked").each(function() {             var value = $(this).attr("value");             total += parseint(value);              });         }      //this happens when page loads     calctotal();         $("h2").after('<p class="total">total: <strong>¥' + total + '</strong></p>');     $("input:checkbox, input:radio").click(function()     {         total = 0;         calctotal();         $("p.total").hide().html("total: <strong>¥" + total + "</strong>").fadein('slow');     }); }); </script> 

give each form different id (e.g. ) , modify selector include form's id:

$('#form1 input:checked').each(function() { 

update: accomplish scoping id on each form, way using scoped selectors. (i'm assuming <h2> contained within form.)

$("h2").after('<p class="total">total: <strong>¥0</strong></p>'); $("input:checkbox, input:radio").click(function() {     var total = 0;     var scope = $(this).parent('form');     $("input:checked", scope).each(function() {         var value = $(this).attr("value");         total += parseint(value, 10);     });     $("p.total", scope).hide().html("total: <strong>¥" + total + "</strong>").fadein('slow'); }); 

you can see in action @ http://jsfiddle.net/7nghq/.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -