Wednesday, September 8, 2010

Numeric textbox javascript...

    <input type='text' onkeydown='text_keydown(event)' />

<script language='javascript' type='text/javascript'>
function text_keydown(e)
{
var key;
document.all ? key = e.keyCode /*IE*/ : key = e.which /*FF*/;
if(!(key > 47 && key < 58) && key != 8 && key != 37 && key != 39 && key != 16 && key != 46)
{
cancelevent(e);
}
}

function cancelevent(e)
{
if(window.event) // IE
{
window.event.returnValue = false;
}
else // FF
{
e.preventDefault();
}
}
</script>

No comments:

Post a Comment