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? ?
Please keep in mind that I am a total newbie at this, so please keep your explanations as simple as possible. Thanks again!
The code follows below:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“
<html xmlns=”
<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>