Created
January 25, 2011 09:55
-
-
Save robotlolita/794728 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
function isNumeric(v) { | |
return !isNaN(+v) // implicit typecasting to Number, taking advantage of JavaScript's type coercion | |
} | |
function checkForm() { | |
var elms_to_test = ['coupon', 'ins', 'quantity', 'ref', 'dr'] | |
, el, i | |
for (i = elms_to_test.length; i--; ) { | |
// use getElementById to get a reference to the element with the given ID. | |
el = document.getElementById(elms_to_test[i]) | |
// you don't need to test against an explicit boolean in javascript, any value considered truthy will do. | |
// truthy values are any other than 0, false, undefined, null and empty string ("") | |
if (!isNumeric(el.value)) { | |
alert('Not numeric') | |
return false }} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment