Skip to content

Instantly share code, notes, and snippets.

@xtina-starr
Created February 3, 2015 23:38
Show Gist options
  • Save xtina-starr/a842b831e62cd1f7b7c7 to your computer and use it in GitHub Desktop.
Save xtina-starr/a842b831e62cd1f7b7c7 to your computer and use it in GitHub Desktop.
JScript 200 WN15 Week 4 Class Exercises
// JScript 200 WN15 Week 4 Class Exercises
//Christina Thompson
// 1) Here is an element which uses HTML5 required attribute:
<input type="text" name="Name" required="required"/>
// 2) Here is how we can validate a single text box:
if($('#Name').val() == '') {
alert('Please enter your name');
$('#Name').focus();
return false;
}
$('#myForm').submit(function(e){
if($('#Name').val() == '') {
alert('Please enter your name');
$('#Name').focus();
// return false;
var colorChecked = $('#FavoriteColor input:radio:checked').length;
if(colorChecked < 1) {
alert("Please choose your favorite color");
$("#FavoriteColor input:radio:checked").focus();
return false;
}
} else {
var name = $("input[name=Name]").val();
var output = "<p>Selections Made:</p>";
output += "</p>Name: " + name + "</p>";
$("#output").html(output);
}
// alert("form submitted!");
e.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment