0

this is my function which is calculating values. But if any of the values is empty it does not calculate the total payment value. if there is any simple way to calculate pls let me know

function startCalc(){
interval = setInterval("calc()",1);}

function calc(){
				
 room_charges = document.ipd_bill.room_charges.value ;
  lab_charges = document.ipd_bill.lab_charges.value;
  consultancy_fees = document.ipd_bill.consultancy_fees.value;
  blood_charges = document.ipd_bill.blood_charges.value; 
organ_charges = document.ipd_bill.organ_charges.value; 
discount = document.ipd_bill.discount.value;
document.ipd_bill.total_payment.value = eval(room_charges) + eval(lab_charges) + eval(consultancy_fees) + eval(blood_charges) + eval(organ_charges) - discount;
}

function stopCalc(){
	clearInterval(interval);
		}
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by hielo
0

try:

function calc(){
				
 room_charges = isNaN(parseInt(document.ipd_bill.room_charges.value)) ? 0 :  parseInt(document.ipd_bill.room_charges.value);
  lab_charges = isNaN(parseInt(document.ipd_bill.lab_charges.value)) ? 0 :  parseInt(document.ipd_bill.lab_charges.value);
  consultancy_fees = isNaN(parseInt(document.ipd_bill.consultancy_fees.value)) ? 0 :  parseInt(document.ipd_bill.consultancy_fees.value);
  blood_charges = isNaN(parseInt(document.ipd_bill.blood_charges.value)) ? 0 :  parseInt(document.ipd_bill.blood_charges.value); 
organ_charges = isNaN(parseInt(document.ipd_bill.organ_charges.value)) ? 0 :  parseInt(document.ipd_bill.organ_charges.value); 
discount = isNaN(parseInt(document.ipd_bill.discount.value)) ? 0 :  parseInt(document.ipd_bill.discount.value);
document.ipd_bill.total_payment.value = eval(room_charges) + eval(lab_charges) + eval(consultancy_fees) + eval(blood_charges) + eval(organ_charges) - discount;
}
0

hielo

It is giving the following error. Actually i am get room charges, lab charges values from database using ajax. Then i am doing the total and subracting discount. if any of the charges is not available it gives the error.

Message: 'document.ipd_bill.room_charges.value' is null or not an object

0

you are probably "erasing" your original field OR the field is not in the DOM when you call the function. Can't tell you for sure without looking at your actual page online!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.