Created
February 26, 2014 12:10
-
-
Save slopeofhope81/9228436 to your computer and use it in GitHub Desktop.
validation example using javascript/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>example javascript</title> | |
</head> | |
<body> | |
<form name="logInForm" method="post" onsubmit="return validate()"> | |
First name:<input type="text" id="firstName" name="firstName" > | |
Last name:<input type="text" id="lastName" name="lastName" > | |
<input type="submit" value="LogIn" id="logIn">////<---------this type comes in pair with onsubtmit attribute!!! | |
<div id="error"></div> | |
</form> | |
<script type="text/javascript" src="do.js"></script> | |
</body> | |
</html> | |
function validate(){ | |
var error=document.getElementById("error"); | |
var firstName = document.forms["logInForm"]["firstName"].value; | |
var lastName = document.forms["logInForm"]["lastName"].value; | |
if (firstName == "" || firstName == null || lastName == "" || lastName == null){ | |
error.innerHTML = "the info must be filled out"; | |
error.style.color = "red"; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment