1

Which Javascript event is fired when someone presses the "return" key on an iPad in Safari while an input is selected.

I'm using an input element, but not surrounding it in <form> tags. I submit the $('#input').value() when $('#button').click() occurs. However, I'd like to also like to be able to submit when someone presses "return" on the iPad keyboard.

I was overzealous, here is the answer:

jQuery Event Keypress: Which key was pressed?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Andrew Samuelsen
  • 5,325
  • 9
  • 47
  • 69

2 Answers2

3

You can detect the enter key event in safari on ipad with following way :

<body onkeyup="yourFunction(event)">

then in javaScript

function yourFunction(event) {
    var e;
    if(event) {
        e = event;
    } else {
        e = window.event;
    }

    if(e.which){
       var keycode = e.which;
    } else {
       var keycode = e.keyCode;
    } 

    if(keycode == 13) {
       alert("do your stuff");
    }
};
BBog
  • 3,630
  • 5
  • 33
  • 64
Anshul Sharma
  • 166
  • 1
  • 5
0

What about using a <form> tag and binding your handler to the submit tag.

$("#myForm").submit(function (event) {
   doStuff();
});

It's cleaner and simpler.

Rahman Kalfane
  • 1,717
  • 17
  • 17
  • probably going to end up doing this, but if you were curious for how to do it based on the keycode check the link i posted. thanks! – Andrew Samuelsen Aug 23 '11 at 23:44