<html>
<head>
<title>Form Validation using JavaScript</title>
</head>
<body>
<form name="form1" action="formvalidation.html" onsubmit="return validate()" method="post">
<input type="text" name="username">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
function validate() {
var x = document.forms["form1"]["username"].value;
if (x == null || x == "") {
alert("Name must be filled out");
return false;
}
}
</script>
</body>
</html>
0 comments:
Post a Comment