PDA

View Full Version : need help validating inputs



dakevs
02-19-2008, 03:19 AM
hey everyone. i am taking a javascript class, and am having some trouble with an assignment. The assignment wants me to ask a user to input 3 values and test if they can make a triangle.

The part where I am stuck is when I am validating the user input to see if they are numbers. I use the "isNan" function. Anyways I copy pasted my code below. Can anyone tell me where I am going wrong? Thanks! :confused:

The code follows below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title> Assignment 2</title>


<script type="text/javascript">
<!--HIDE FROM INCOMPATIBLE BROWSERS

function isNumber(element) {
var testNumber = isNan(element);
if (testNumber == true) {
window.alert("Please enter a number!");
return false;
}
}


// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>


</head>

<body>


<h1>Assignment 2</h1>
<p>Enter 3 numbers that you would like to test for below.</p>

<form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded">

<p>Number 1: <input type="text" name="first_number" size="10" onchange="return isNumber(this.value);" /></p>
<p>Number 2: <input type="text" name="second_number" size="10" onchange="return isNumber(this.value);" /></p>
<p>Number 3: <input type="text" name="third_number" size="10" onchange="return isNumber(this.value);" /></p>


</form>


</body>
</html>

dakevs
02-19-2008, 03:21 AM
Oh yea, please remember that I am a newbie to this. I would appreciate it if you tried to keep your explanations as simple as possible. Thanks again! :)

codeexploiter
02-19-2008, 04:15 AM
The problem seems to be the following item:


var testNumber = isNan(element);


The function name is not isNan but isNaN


var testNumber = isNaN(element);


If you correct this I think it should work

Master_script_maker
02-19-2008, 09:56 PM
do you also need to help with seeing if the numbers can be angles for a triangle?