[Javascript] combining if statements

Walter Torres walter at torres.ws
Fri Feb 7 11:28:39 CST 2003


Tell me if this does what your looking for?

Walter


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<body>

<form id='openp5'>

books1beg:<br>
<input type='text' name='books1beg' id='books1beg' value='2'>
<p>

books2add:<br>
<input type='text' name='books2add' id='books2add' value='5'>
<p>

books3weed:<br>
<input type='text' name='books3weed' id='books3weed' value='100'>
<p>

<button onClick='getAnswer ()'>Calc</button>
<p>

Answer is!:<br>
<input type='text' name='answer' id='answer' value='Well?'>
<p>

</form>

</body>

<script>

var K = evalData ( openp5.books1beg.value );
var L = evalData ( openp5.books2add.value );
var M = evalData ( openp5.books3weed.value );


function evalData ( strValue )
{
	// Force to lower case for consistant string comparision
	strLCvalue = strValue.toLowerCase();

	// NR,nr, NA, na and -1 need to have the value of 0.
	// If the given value is one of these, make it a ZERO,
	// otherwise kick it back as given!
	return  ( strLCvalue == 'nr')   ||
			( strLCvalue == 'na'  ) ||
			( strLCvalue == ''    ) ||
			( strLCvalue == '-1'  ) ? 0 : Number (strValue);

}

function getAnswer ()
{
	openp5.answer.value = ( K + L ) - M;
}

</script>

</html>



More information about the Javascript mailing list