mercredi 28 septembre 2016

Add only those textbox value whose respective check box is checked

<input type="checkbox" id="checkbox1" />  
<input id="reg11" type="text" name="add-1" class="form-control" value="22" readonly ><br>
<input type="checkbox" id="checkbox2" /> 
<input id="reg11" type="text" name="add-2" class="form-control" value="22" readonly ><br>
<input type="checkbox" id="checkbox3" /> 
<input id="reg11" type="text" name="add-2" class="form-control" value="22" readonly >  

I have three textboxes and respective checkboxes. I want to add only those text box value whose respective checkbox is checked.

jQuery(document).ready(function($) {
    var sum = 0;
    $('#checkbox1').click(function() {
       sum = 0;
       var val1= parseInt($("#add-1").val()); 
       var val2= parseInt($("#add-2").val()); 
       sum=parseInt(val1+val2);
       $('#sum').html(sum);
    });
});




Aucun commentaire:

Enregistrer un commentaire