Created
February 1, 2013 15:43
-
-
Save cfjedimaster/4692083 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
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$("#commentForm").validate({ | |
submitHandler: function(form){ | |
var fields = $("input.numeric"); | |
var total = 0; | |
fields.each(function(x,item) { | |
var val = $(this).val(); | |
if(val != "") total += parseInt(val,10); | |
}); | |
console.log(total); | |
if (total != 100) { | |
$("#commentForm div.error").html("Your percantage fields must sum to 100.") | |
return false; | |
} else form.submit(); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form id="commentForm" method="get" action=""> | |
<fieldset> | |
<legend>A simple comment form with submit validation and default messages</legend> | |
<p> | |
<label for="pA">Percent A</label> | |
<em>*</em><input id="pA" name="pA" size="2" type="number" class="numeric" min="1" max="100" /> | |
</p> | |
<p> | |
<label for="pB">Percent B</label> | |
<em>*</em><input id="pB" name="pB" size="2" type="number" class="numeric" min="1" max="100" /> | |
</p> | |
<p> | |
<label for="pC">Percent C</label> | |
<em>*</em><input id="pC" name="pC" size="2" type="number" class="numeric" min="1" max="100" /> | |
</p> | |
<p> | |
<input class="submit" type="submit" value="Submit"/> | |
</p> | |
</fieldset> | |
<div class="error"></div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment