I have list of check boxes with certain amounts.
<input type="checkbox" name="subject1" value="course_id" amount_t="amount" class="amount" />
<input type="checkbox" name="subject2" value="course_id" amount_t="amount" class="amount" />
<input type="checkbox" name="subject3" value="course_id" amount_t="amount" class="amount" />
<input type="checkbox" name="subject4" value="course_id" amount_t="amount" class="amount" />
$(document).ready(function(){
$(".amount").change(function(){
if (($(this).is(':checked'))) {
var res;
var val1 = parseInt($(this).attr("amount_t"));
var val2 = $("#amount").attr("value");
console.log('value1',val1);
console.log('value2',val2);
res = val2.slice(-4);
res = parseInt(res);
var val3 = 'Amount : $ ';
var val4 = val1 + res;
var val = val3 + val4;
$("#amount").val(val);
}
else{
var res;
var val1 = parseInt($(this).attr("amount_t"));
var val2 = $("#amount").attr("value");
console.log('value1',val1);
console.log('value2',val2);
res = val2.slice(-4);
res = parseInt(res);
var val3 = 'Amount : $ ';
var val4 = res - val1;
var val = val3 + val4;
$("#amount").val(val);
}
});
});
Amount should not able to change by user.
it is is working fine for first selection, after that it is showing like initial. can you please help me.
Aucun commentaire:
Enregistrer un commentaire