0
<html><input id="test" type="text" /></html>
<script>
    $(function(){
        $("#test").keypress(function(event)
        {
            if ((event.charCode == 32) || (event.charCode == 64))
                alert("Working with space & @ but not with Enter");
        });
    });
</script>

Here is my code but it's not working for ascii of 'Enter' which is '13'

lifeisbeautiful
  • 817
  • 1
  • 8
  • 18
9i8s
  • 1
  • 1

1 Answers1

0

You can use "event.which" instead of "event.charCode" to get the key pressed. event.which will return 13 for enter key pressed.

Example:

var code = event.charCode || event.which;
 if(code == 13) { //Enter keycode
   //Do something
 }
Preeti
  • 152
  • 1
  • 8