我正在尝试创建一个简单的验证脚本来检查文本是否输入到文本框中。我编写了以下代码,不幸的是它没有打印警报。
<html>
<head>
<title> Js Page </title>
<script>
function validateName()
{
var FirstName=document.forms["myForm"]["firstname"].value;
if(FirstName==null || FirstName=="" )
{
alert("Please insert the corect First/Lastname");
return false;
}
}
</script>
</head>
<body>
<form name = "myForm" onsubmit = "return validateName()" method="post">
First name: <input type="text" name="firstname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>