/    Sign up×
Community /Pin to ProfileBookmark

need help validating inputs

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsFeb 19.2008 — [CODE]<!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>
<form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded">

<p>Number 1: <input type="text" name="first_number" size="10" onkeyup="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" onblur="return isNumber(this.value);" /></p>


</form>
[/CODE]
Copy linkTweet thisAlerts:
@dakevsauthorFeb 19.2008 — i applied the changes you made to my input fields, yet it still doesn't work... ARGHHHHHHHHHHHHHHHHHH. Internet explorer gives me an error message, of "expected object" Line 15, Char: 2... what the hell!
Copy linkTweet thisAlerts:
@dakevsauthorFeb 20.2008 — anyone, please?
Copy linkTweet thisAlerts:
@vwphillipsFeb 20.2008 — Note

var testNumber = isNa[COLOR="Red"]N[/COLOR](element);



I changed the input event types to demonstrate alternatives
Copy linkTweet thisAlerts:
@dakevsauthorFeb 27.2008 — argh. thank you. i feel so stupid! i didn't notice that the second n had to be capitalized! :eek:
×

Success!

Help @dakevs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...