Created
May 30, 2013 08:42
-
-
Save azrad/5676549 to your computer and use it in GitHub Desktop.
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
<form> | |
<div class="control-group"> | |
<label for="name" class="control-label">Name</label> | |
<div class="controls"> | |
<input type="text" name="name" id="name" class="required" /> | |
</div> | |
</div> | |
<div class="control-group"> | |
<div class="controls"> | |
<input type="submit" value="Submit" /> | |
</div> | |
</div> | |
</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
jQuery(document).ready(function() { | |
$("form").on('submit', function() { | |
var ok = true; | |
$('.control-group').removeClass('error'); | |
$('.required').each(function() { | |
if ($(this).val() == "") { | |
ok = false; | |
$(this).closest('.control-group').addClass('error'); | |
} | |
}); | |
$('.error').first().find('input').focus(); | |
if (!ok) { | |
return false; | |
} | |
return true; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment