Created
November 29, 2014 00:12
-
-
Save ihsanberahim/aa4ee5604032bedee2b2 to your computer and use it in GitHub Desktop.
Block input example
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> | |
<body onload="onBodyLoad()"> | |
<input name="intergerField"/> | |
</body> | |
</html> |
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
window.integerOnly = function(elem) { | |
if (event.keyCode>=48 && event.keyCode<=57){ | |
}else | |
{ | |
return false; | |
} | |
return true; | |
}; | |
function onBodyLoad() | |
{ | |
document.querySelector('input[name="intergerField"]').setAttribute('onkeydown',"return integerOnly(this)"); | |
} | |
/* | |
CREDIT | |
http://ihsanberahim.com | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment