I have started a new JavaScript task, which tells me to validate a form with a field and a button. Whenever I type in a random number, an alert box should appear with an answer 'The number is bigger/smaller than 10'. So far so good-I did that part of the task. The problem appears, when I type in the letter-the alert box appears anyway. How could this be fixed?
Code looks like this:
function validate(){
x=document.myForm
txt=x.myInput.value
if (txt>=10)
{
alert("Number is bigger than 10")
return true
}
else
{
alert("Number is smaller than 10")
return false
}
}
<form name="myForm" onsubmit="return validate()">
Enter a number:
<input type="text" name="myInput" size="20">
<input type="submit" value="Submit">
Thank you for your answers!