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!
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>




Reply With Quote



Bookmarks