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'

0

1 Answer 1

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
 }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.