Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript "return false" from onkeypress handler

Tags:

javascript

I used code in the below method to block my keyboard and it worked for me.

<asp:textbox id="t1" onkeypress="return false;" />

Now I want to add some more for for it and I tired to do the same using extra code as

<script type="text/javascript">
fuction disablekeys()
{
return false;
}
</script>
<asp:textbox id="t1" onkeypress="disablekeys();" />

But this code is not working. Why?

like image 793
Mad coder. Avatar asked Oct 14 '11 22:10

Mad coder.


1 Answers

You need to return the value returned by disablekeys:

<asp:textbox id="t1" onkeypress="return disablekeys();" />

Your new onkeypress handler currently ignores this value.

like image 105
Wayne Avatar answered Sep 19 '22 20:09

Wayne