You could be explicit about it with the parseFloat (or parseInt)
functions. They convert text into numerics. The related function isNaN
checks whether an attempted conversion was successful.
Here's some code that uses the parseFloat function.
---- CUT SCREEN HERE ----
function check_number(num)
//check whether num is a number
{
n=parseFloat(num);
if (isNaN(n))
return 0;
else
return n;
}
function compute_max_payment()
{
expense=0;
inflow=check_number(income.innerText);
expense+=check_number(car.innerText);
expense+=check_number(utilities.innerText);
expense+=check_number(living.innerText);
expense+=check_number(other1.innerText);
expense+=check_number(other2.innerText);
expense+=check_number(other3.innerText);
expense+=check_number(other4.innerText);
pay=inflow-expense;
total_expenses.innerText=expense;
housing_payment.innerText=pay;
}
----- CUT SCREEN HERE -----
Seems to work. The innerText is a DHTML property - could easily be a form
field.
This is why I don't care for weakly typed languages.
-------------------------------------------------------------------------
Kieran Mathieson Office: Varner 217N
Department of Decision and Information Sciences Voice: (248) 370 3507
School of Business Administration FAX: (248) 370 4275
Oakland University
Rochester, MI 48309 Internet: mathieso @ oakland.edu
-------------------------------------------------------------------------
____________________________________________________________________
--------------------------------------------------------------------
Join The Web Consultants Association : Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------