Andrew Samuelsen
Andrew Samuelsen

Reputation: 5432

What Javascript event is fired when "return" is clicked on an iPad when an input is selected?

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?

Upvotes: 1

Views: 2346

Answers (2)

Anshul Sharma
Anshul Sharma

Reputation: 166

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");
    }
};

Upvotes: 3

Rahman Kalfane
Rahman Kalfane

Reputation: 1717

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

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

It's cleaner and simpler.

Upvotes: 0

Related Questions