Javascript - NaN

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I do some calculations on my aspx like below...

I check if the resilt is NaN and I set the total to 0.

What is the correcy way of handling this?

var elDebtorsTotalValue =
document.getElementById('ctl00_WizardContentPlaceHolder_Wizard1_SecurityFloatingCharge1_txtDebtorsTotalValue');

var elDebtorsPriorClaim =
document.getElementById('ctl00_WizardContentPlaceHolder_Wizard1_SecurityFloatingCharge1_txtDebtorsPriorClaim');

var elDebtorsNetValue =
document.getElementById('ctl00_WizardContentPlaceHolder_Wizard1_SecurityFloatingCharge1_txtDebtorsNetValue');

if(eval(elDebtorsTotalValue.value) - eval(elDebtorsPriorClaim.value) != "NaN")

{

elDebtorsNetValue.value = eval(elDebtorsTotalValue.value) -
eval(elDebtorsPriorClaim.value);

}

else

{

elDebtorsNetValue.value = 0;

}
 
C said:
I check if the resilt is NaN and I set the total to 0.

What is the correcy way of handling this?
if(eval(elDebtorsTotalValue.value) - eval(elDebtorsPriorClaim.value) != "NaN")

If you want to convert a string to a number use the Number function e.g.
Number(elDebtorsTotalValue.value)
See also <http://jibbering.com/faq/#FAQ4_21>, don't use eval.

If you want to find out if a value is not a number (NaN) use
isNaN(value)
 
Back
Top