Skip to content

Instantly share code, notes, and snippets.

@efecarranza
Created February 6, 2015 16:39
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 efecarranza/54d4c5669fef4b3cbf3d to your computer and use it in GitHub Desktop.
Save efecarranza/54d4c5669fef4b3cbf3d to your computer and use it in GitHub Desktop.
All In One - Input Validation jQuery work
CSS file
.error {
color: red;
}
JavaScript/jQuery file
$(function() {
// console.log("inside function");
$('form').on("submit", function(input) {
input.preventDefault();
// console.log($(this).find('#value').val());
if ($(this).find('#value').val() === "Wyncode") {
// console.log("inside wyncode");
} else {
$(this).find('#value').addClass("error");
// console.log("inside else");
}
})
})
HTML file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Input Validation</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
</script>
</head>
<body>
<form>
Name: <input type="text" id='value'>
<input type="button" value="submit">
</form>
<script src="jscript.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment