Skip to content

Instantly share code, notes, and snippets.

@cflove
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cflove/c30f3d4ab46aa4362062 to your computer and use it in GitHub Desktop.
Save cflove/c30f3d4ab46aa4362062 to your computer and use it in GitHub Desktop.
form
<!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