Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When press enter key on textbox it show unwanted popup .i want to disable enter key event on text box.use below script but not working
JavaScript
<pre lang="xml"><script type="text/javascript">
   $(function() {
    $("form").bind("keypress", function(e) {
          if (e.keyCode == 13) return false;
    });
});
   </script>



How to disable enter key event when press enter key on text box using c# asp.net.
Posted

See the same Answered question on CP:
How to Prevent Enter Key for TextBoxes[^]


--Amit
 
Share this answer
 
use this java script function

JavaScript
function checkShortcut() {
           if (event.keyCode == 13) {
               alert("Enter key is not allowed");
               return false;
           }
       }


Use this function is text box

and add this line in text box

C#
onkeydown="return checkShortcut();"
 
Share this answer
 
$('#myTextBoxID').keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});

You can use above code to Disable enter key on textbox.
 
Share this answer
 
This is the cross browser solution

C#
var texts = $("#textBoxID").bind("keydown", function (event) {
    var key = event.keyCode ? event.keyCode : event.charCode;
    if (key == 13) {
        if (!event)
            event = window.event;
        event.stopPropagation();
        event.preventDefault();
        event.returnValue = false;
        return false;
    }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900