Created
February 3, 2015 23:38
-
-
Save xtina-starr/a842b831e62cd1f7b7c7 to your computer and use it in GitHub Desktop.
JScript 200 WN15 Week 4 Class Exercises
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
// 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