Skip to content

Instantly share code, notes, and snippets.

@defeated
Created October 2, 2009 16:17
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 defeated/199869 to your computer and use it in GitHub Desktop.
Save defeated/199869 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
jQuery(function($){
$.fn.num = function(){
var val = $(this).val();
return (isNaN(val) || val == null) ? 0 : parseInt(val);
}
});
</script>
<!-- usage -->
<form id="sample">
<input type="text" id="field" />
</form>
<script type="text/javascript">
$('#sample').submit(function(){
alert($('#field').num() * 10);
return false;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment