views:

511

answers:

2

I'm having trouble with AJAX form submitting on the iphone. I have a search field at the top with no submit button. My plan is to submit the form when the user hits "Go" or "Search" on the iphone keyboard. Anybody got any ideas?

Edit: I have the ajax working but I cant seem to get the keyboard to close after I press search.

Here is the code:

<form id="searchForm" method="post" onsubmit="event.preventDefault(); showSearch(search.value);">
     <input type="text" name="search" id="searchField">
</form>

Thanks! I got it. Who knew it could be so simple. I just added search.blur(); to the onsubmit.

+1  A: 

To remove the keyboard, all you need to do is remove focus on that particular field. You can do this with JavaScript.

August
A: 

Years ago I was trying to use a barcode scanner built into one of those retail inventory management hand-helds with the built-in web browser. It was for a warehouse management system and I wanted to make it web-based. There was a third-party browser that would run on the device.

So I have an input box that the barcode scanner would "type" into (it behaved like a keyboard wedge). The problem I had is there was no way for the barcode scanner to press RETURN to initiate the search, which is similar to your problem. The device too had a virtual keyboard, so people could open it and then press return, but that just ruined the flexibility of the aim-and-shoot the barcode scanner offered.

The solution I came up with was to run a timer to see if the contents of the input box changed. If nothing changed after a certain period, I assumed the input was done, and I forced a submit.

This may work for you too.

Diodeus