Im trying to calulate the sum of the checked boxes with simple javascript.
I have a 3 check boxes. On selecting two (ambassador_pack, business_ambassador_licence) of them the sum is auto calculated and stored in TotalAmount.
One check box has a text box where the user enters the quantity for the prodects... quantity * cost(95) is calculated and added to the TotalAmount.
I get Error, when I keyin the quantity: "Error: document.getElementById("kids_ambassador_pack_qty") is null"
Code: Select all
<input type="checkbox" id="ambassador_pack" name="ambassador_pack" value="195" onclick="readAmPak('ambassador_pack');" />
Ambassador Pack $195</label>
<br/>
<label><input type="checkbox" id="kids_ambassador_pack" name="kids_ambassador_pack" value="95" > Kids Ambassador Pack</label>
($95 per pack)
<br />
$95 x
<input type="text" name="kids_ambassador_pack_qty" value="" size="5" onchange="readQty('kids_ambassador_pack_qty');" //> enter qunatity<br/>
<label><input type="checkbox" id="business_ambassador_licence" name="business_ambassador_licence" value="1000" onchange="readAmlic('business_ambassador_licence');" >
Business Ambassador Licence $4850</label>
[<label>Initial 'Hold-a-slot-for-Me' $1000]</label>
<br><br>
Total Amount
<input name="total_amount" type="text" id="total_amount" style="background: #FF9900; text-align:right; font-weight:bold; color:black;" size='12' maxlength="50" disabled/>
Code: Select all
function readAmPak(qtyfield){
if(document.frmSS17.ambassador_pack.checked == true){
if (document.getElementById("total_amount").value ==""){
subTotal = parseInt(document.getElementById("ambassador_pack").value);
}else{
subTotal = parseInt(document.getElementById("total_amount").value) + parseInt(document.getElementById("ambassador_pack").value);
}
document.getElementById("total_amount").value = Math.round(subTotal*100)/100 ;
}
//--------
if(document.frmSS17.ambassador_pack.checked == false){
if (document.getElementById("total_amount").value ==""){
subTotal = parseInt(document.getElementById("ambassador_pack").value);
}else{
subTotal = parseInt(document.getElementById("total_amount").value) - parseInt(document.getElementById("ambassador_pack").value);
}
document.getElementById("total_amount").value = Math.round(subTotal*100)/100 ;
}
}
function readQty(qtyfield){
document.frmSS17.kids_ambassador_pack.checked = true;
if (!(document.getElementById("kids_ambassador_pack_qty").value =="")){
var qtykidam_pk = document.getElementById("kids_ambassador_pack_qty").value;
qtykidam_pk = qtykidam_pk * 1;
alert("kids_ambassador_pack_qty "+document.getElementById("kids_ambassador_pack_qty").value);
if (isNaN(qtykidam_pk)) {
qtykidam_pk = 0;
alert("Months have to be numerical");
document.getElementById("kids_ambassador_pack_qty").focus();
}
subTotal = parseInt(document.getElementById("total_amount").value) + (95 * parseInt(document.getElementById("kids_ambassador_pack_qty").value));
document.getElementById("total_amount").value = Math.round(subTotal*100)/100;
}
alert("kids_ambassador_pack_qty "+document.getElementById("kids_ambassador_pack_qty").value);
}
function readAmlic(qtyfield){
if(document.frmSS17.business_ambassador_licence.checked == true){
subTotal = parseInt(document.getElementById("total_amount").value) + parseInt(document.getElementById("business_ambassador_licence").value);
document.getElementById("total_amount").value = Math.round(subTotal*100)/100;
}
//--------
if(document.frmSS17.business_ambassador_licence.checked == false){
if (document.getElementById("total_amount").value ==""){
subTotal = parseInt(document.getElementById("business_ambassador_licence").value);
}else{
subTotal = parseInt(document.getElementById("total_amount").value) - parseInt(document.getElementById("business_ambassador_licence").value);
}
document.getElementById("total_amount").value = Math.round(subTotal*100)/100;
}
}
Any suggestion/ ideas how to fix this error guys?
Thanks, much appreciated