Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture the keyboard "Return" event on iPhone browser?

Is there a way to capture the event in jquery/javascript when a user hits the "Return" key in the iphone browser keyboard? I'm trying to either hide the keyboard on the press or activate some function.

like image 432
locoboy Avatar asked Feb 02 '23 18:02

locoboy


2 Answers

You could try this:

<script type="text/javascript">
document.onkeyup=function(e) {
    if(e.which == 13){
        $('inputID').blur();
        //rest of function

        return false;
    }
}
</script>

Are you using a library?

Update
Depending on the application, an input submit would hide the keyboard and trigger a function:

<form id="searchForm" OnSubmit="doSearch(this.searchTerm.value); return false;">  
  <input type="search" name="searchTerm" autocorrect = "off" />
  <input type="submit" value="Search" class="hidden" />
</form>

You could even hide the input button with CSS: .hidden {display: none;}

like image 185
Josiah Avatar answered Feb 06 '23 06:02

Josiah


This is what hides the keyboard:

$('#inputID').blur();
like image 30
locoboy Avatar answered Feb 06 '23 04:02

locoboy