Skip to content

Instantly share code, notes, and snippets.

@0xgdr
Created December 15, 2012 21:31
Show Gist options
  • Select an option

  • Save 0xgdr/4299418 to your computer and use it in GitHub Desktop.

Select an option

Save 0xgdr/4299418 to your computer and use it in GitHub Desktop.
Lesson from Treehouse, using jquery.
function isValidEmail(email) {
return email.indexOf("@") != -1;
}
// get all the inputs with the class of required
var $required = $('.required');
function requiredValues() {
var $values = new Array();
$required.each(function() {
$values.push($(this).val());
});
return $values;
}
function containsBlanks() {
var blanks = new Array();
$required.each(function() {
blanks.push($(this).val() == "");
});
return $.inArray(true, blanks) != -1;
}
<!DOCTYPE html>
<html>
<head>
<title>Modifying Attributes</title>
<style type="text/css">
.valid {
color: green;
border: 2px solid green;
}
.error {
color: red;
border: 2px solid red;
}
</style>
</head>
<body>
<p>
<input type="text" class="required" id="name" value="Andrew">
</p>
<p>
<input type="text" class="required" id="company" value="Treehouse Island, Inc">
</p>
<p>
<input type="text" class="" id="phone" value="555-123-4567">
</p>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment