0

my previous question:

This

sweetamylase posted her fiddle http://jsfiddle.net/amyamy86/jSyfy/ , which is great and very close to what I am trying to achieve, but I am having trouble getting it so that pressing enter will trigger the same as clicking the button.

I tried this and other variations

$("input").keypress(function(event) {
    if (event.which == 13) {
        event.preventDefault();
       FoodDispaly();
    }
});

but haven't gotten it to work

1
  • Need more code to understand what exactly is going on here. Make a jsFiddle with your code and then post that. Commented Apr 9, 2013 at 15:52

2 Answers 2

4

Personally, I've always had problems with keypress. Use keyup instead. I've modified the fiddle linked to you in your first post to handle keyup:

$("#inputFoodChoice").keyup(function (e) {
                var code = (e.keyCode ? e.keyCode : e.which);
                if (code == 13) { //Enter keycode
                    e.preventDefault();
                    checkInputValue(e);
                }
}); 

http://jsfiddle.net/jSyfy/1/

Sign up to request clarification or add additional context in comments.

Comments

1

To go with your problem, add this right after the button click handler:

$("#inputFoodChoice").keyup(function(event) {
    if (event.which == 13) {
        checkInputValue();
    }
});

See fiddle: http://jsfiddle.net/jSyfy/2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.