Last active
August 29, 2015 14:17
-
-
Save cflove/c30f3d4ab46aa4362062 to your computer and use it in GitHub Desktop.
form
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Untitled Document</title> | |
</head> | |
<style> | |
.error {color:red} | |
</style> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<body> | |
<form action="http://google.com" method="post" id="myForm"> | |
<div class="box"> | |
<div class="label"> | |
First Name | |
</div> | |
<div class="inputs"> | |
<input type="text" id="firstname" size="30"> | |
</div> | |
</div> | |
<div class="box"> | |
<div class="label"> | |
Last Name | |
</div> | |
<div class="inputs"> | |
<input type="text" id="lastname" size="30"> | |
</div> | |
</div> | |
<div class="box"> | |
<div class="label"> | |
</div> | |
<div class="inputs"> | |
<button type="submit">Submit</button> | |
</div> | |
</div> | |
</form> | |
<script> | |
$('#myForm').submit(function(e){ | |
a = $('#lastname').val() | |
if (a == '' ) { | |
$('#lastname').parent().prev().addClass('error') | |
alert('Please Fill the form') | |
return false; | |
} | |
}) | |
$('#lastname').keypress(function(){ | |
$('#lastname').parent().prev().removeClass('error') | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment