The problem is that you're trying to use them as if there's a valid numeric value in them. Before trying to use the values in those fields, check to see if they're
NaN
, and only then, do the desired math operations. In fact, I'd do this:
var TxtSTUPort = document.getElementById(TxtSTUPort);
var TxtAAPort = document.getElementById(TxtAAPort);
var STD_NUM_OF_SERVING = document.getElementById(STD_NUM_OF_SERVING);
var stuPort = 0;
var aaPort = 0;
var numServing = 0;
if (TxtSTUPort != null && TxtSTUPort.value != null)
{
stuPort = TxtSTUPort.value;
}
if (TxtAAPort != null && TxtAAPort.value != null)
{
aaPort = TxtAAPort.value;
}
if (STD_NUM_OF_SERVING != null)
{
STD_NUM_OF_SERVING.value = stuPort + aaPort;
}
Id also take steps to ensure that the data IN the text fields is valid numeric data. I'm not big on JavaScript, but I'm sure there's code somewhere to do that (and the code above may need to be tweeked since I'm not sure if comparing against
null
is valid in Javascript).