Mulone
Mulone

Reputation: 3663

Search input text field on Android with Chrome browser

I'm trying to implement a simple search button on a web app for Android. I would like the search to start immediately (via AJAX) after the user enter text. This is the input button:

      <div data-role="fieldcontain" data-controltype="searchinput">
          <input name="" id="main_search" placeholder="" 
          value="Search for stuff" onblur="alert('onblur');"
          onclick="alert('onclick');"
          onfocus="if(this.value == 'Search for stuff') { this.value = ''; }" type="search">
      </div>

In this version, the user can click on the input field, enter text on the Android keyboard, but then when tapping on "go", nothing happens, and the keyboard stays open (so the 'onblur' is never fired). What would be a good solution to this issue?

Thanks, Mulone

Upvotes: 1

Views: 1043

Answers (1)

bgse
bgse

Reputation: 8587

What about checking for enter keypress in the input field, and then triggering your search when it is pressed?

$('#inputField').keypress(function(e) {
    if(e.which == 13) {
        //trigger search here
        //possibly just fire the onclick manually
    }
});

That is assuming the 'go' button on the onscreen keyboard is giving enter keycode, but I think it does.

Upvotes: 1

Related Questions