How do I alert that the user input in not a number?

wxdqz

New Member
Okay, I'm a little confused. I need to alert if the information that a user submits is in fact a number, if it is not, I have to alert that the values are invalid. Should I use and if statement to do this? Here is my code:

<html>
<head>
<title>calculate interest</title>
</head>
<body>
<script language="Javascript">
function calculateInterest()
{
var principal = parseFloat(document.myForm.principal.value);
var interestRate= parseFloat(document.myForm.interestRate.value);
var numberOfYears= parseFloat(document.myForm.numberOfYears.value);
for (var i = 0; i < numberOfYears; i++)
{
principal = (principal * interestRate) + principal;
}
alert(principal);
}
</script>
<form name="myForm">
<input type="text" name="principal">Principal<br>
<input type="text" name="interestRate">Interest Rate<br>
<input type="text" name="numberOfYears">Number Of Years<br>
<input type="button" value=http://www.webdeveloper.com/forum/archive/index.php/"Calculate" onClick="calculateInterest()">
</form>
</body>
</html>
 
Back
Top