Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 26, 2014 12:10
Show Gist options
  • Save slopeofhope81/9228436 to your computer and use it in GitHub Desktop.
Save slopeofhope81/9228436 to your computer and use it in GitHub Desktop.
validation example using javascript/
<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