Tip: Prevent non-integer input
March 31st, 2008 | Published in Google Desktop API
Certain gadgets, such as calculators or leap year finders, should restrict user input to integer values. To detect when the user starts entering non-integer data into an element such as an edit area, you can use an
onkeypress
handler:
function onKeyPress() {Have a tip you'd like to share? Send it to gd-developer AT google DOT com. To see all tips, choose the Tips label.
var a = editbox.value;
if (a*1 == a) {
// continue the action
} else {
// show an error message
}
}