Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created January 25, 2011 09:55
Show Gist options
  • Save robotlolita/794728 to your computer and use it in GitHub Desktop.
Save robotlolita/794728 to your computer and use it in GitHub Desktop.
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