JavaScript "return false" from onkeypress handler

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

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

Now I want to add some more for this, and I'm tired of doing the same with extra code like

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

But this code does not work. Why?

+4
source share
1 answer

You need to return the value returned by disablekeys :

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

Your new onkeypress handler is currently ignoring this value.

+12
source

All Articles