Edit This Code:
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
    var x = document.forms["myForm"]["fname"].value;
    if (x == null || x == "") {
        alert("Name must be filled out");
        return false;
    }
}
</script>
</head>
<body>

<form name="myForm" action="demo_form.asp"
onsubmit="return validateForm()" method="post"
>

Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy