Default To The Numeric, Email, And URL Keyboards On The iPhone

Posted September 29, 2009 at 8:58 AM

Tags: HTML / CSS

A long time ago, it used to work on the iPhone Safari browser that if your form inputs had the term "zip" or "phone" in the form field name, clicking on it would default the resultant iPhone keyboard to a numeric keyboard. While this forced us to use some really poor naming conventions, it increased the usability of our web-based iPhone applications in a very palpable way, removing unnecessary clicks for data entry. Unfortunately, this feature was lost somewhere among the many subsequent iPhone firmware updates.

It felt like all was lost and there was no hope... until now. Dorinake, in the comments of my previous post, just explained that if he changed the Type attribute of his form inputs to "number" then he would get the numeric keyboard on the iPhone browser. I also confirmed this, and after doing a bit more testing, it looks like the iPhone now (in the latest firmware updates) supports a small sub-set of the HTML 5 input types:

  • Number
  • Email
  • Url

To test this, I set up a tiny sample page to see how each of these input Types would default the keyboard on the iPhone:

 Launch code in new window » Download code as text file »

  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • <html>
  • <head>
  • <title>Defaulting The iPhone Keyboard To: Number, Email, Url</title>
  • </head>
  • <body>
  •  
  • <h1>
  • Defaulting The iPhone Keyboard To: Number, Email, Url
  • </h1>
  •  
  • <form>
  •  
  • Type="Number":<br />
  • <input type="number" /><br />
  • <br />
  •  
  • Type="Url":<br />
  • <input type="url" /><br />
  • <br />
  •  
  • Type="Email":<br />
  • <input type="email" /><br />
  •  
  • </form>
  •  
  • </body>
  • </html>

As you can see, the Type attributes of the above Input fields are Number, Url, and Email respectively. When I open this page on my iPhone browser and click on the individual form fields, here are the keyboards that I get:

iPhone Input Type="Number"

 
 
 
 
 
 
Using Type = Number Defaults The iPhone Keyboard To The Numeric Keyboard. 
 
 
 

iPhone Input Type="Url"

 
 
 
 
 
 
Using Type = URL Defaults The iPhone Keyboard To The URL Keyboard. 
 
 
 

iPhone Input Type="Email"

 
 
 
 
 
 
Using Type = Email Defaults The iPhone Keyboard To The Email Keyboard. 
 
 
 

This is so awesome! And, what's great is that any browser that doesn't recognize these new HTML 5 input types will simply treat the input as a Text input. As such, this is completely backwards compatible. After discussing this insight with some people, it seems that even on the some of the most up-to-date phones, there are people who are not seeing the appropriate keyboards; we're not sure why this is happening but, there's certainly no harm in putting in the appropriate input types in the meantime.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page


You Might Also Be Interested In:



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Sep 29, 2009 at 9:10 AM // reply »
207 Comments

Woot. Thanks for sharing this. I wonder if Apple updated their docs? The last time I did research into this, they _did_ have decent documentation about writing web apps for the iPhone, so I'd be willing to bet they have this documented.


Sep 29, 2009 at 9:15 AM // reply »
6,516 Comments

@Raymond,

Would you mind posting a link the docs? I am not sure where they are.


Sep 29, 2009 at 9:16 AM // reply »
6,516 Comments

What's exciting about this is that due to the MMS updates, I am sure most everyone is going to be updating their iPhones; which means, most people will get this updates.


Sep 29, 2009 at 9:19 AM // reply »
207 Comments

Will do - I'm in the middle of my own blog post though. ;)


Sep 29, 2009 at 9:20 AM // reply »
6,516 Comments

@Raymond,

No worries :)


Sep 29, 2009 at 9:30 AM // reply »
177 Comments

I thought we had this worked out between you two? No overlapping blog authoring. Whomever goes first, must wait at least 30 minutes before the next person can start authoring their post. Sheesh.


Sep 29, 2009 at 9:32 AM // reply »
207 Comments

"There can be only one."

I'm looking now Ben. I'm now remembering how much of a pain in the ass Apple's site is. I can say that it does NOT require the 99 dollar program fee. Digging now.


Sep 29, 2009 at 9:33 AM // reply »
207 Comments

Well I found it:

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html

But while it mentions some special stuff in forms, it does not mention what you found.


Sep 29, 2009 at 9:37 AM // reply »
6,516 Comments

@Todd,

HA ha.

@Raymond,

Awesome! I don't think I've every seen that page AND I have actually tried to find good documentation on this stuff (granted via Google rather than Apple's site). Thanks.


Sep 29, 2009 at 9:40 AM // reply »
207 Comments

More data:

http://ajaxian.com/archives/html5-features-in-latest-iphone-application-cache-and-database

FYI, the db stuff is incredibly cool and no one (that I know of) is working with this yet. It's much like the db support for AIR, but the browser itself supports it. I've meant to look into it, but haven't yet.

The second item described there looks to be real nice for web based HTML apps for the iPhone.


Sep 29, 2009 at 9:42 AM // reply »
207 Comments

More URLs: The db stuff is freaking incredible: http://blog.bemoko.com/2009/09/16/cool-iphone-handles-the-html5-onstorage-event-handler/


Sep 29, 2009 at 9:43 AM // reply »
6,516 Comments

@Raymond,

Awesome stuff! I'll definitely be looking into it.... when I can find the time :(


Sep 29, 2009 at 9:46 AM // reply »
207 Comments

Last URL, I promise. ;) The Safari in the newest iPhone also supports geolocation:

http://blogs.computerworld.com/iphones_safari_browser_to_include_geolocation_0

I confirmed it on my iPhone (it also works in FF3.5).


Sep 29, 2009 at 11:19 AM // reply »
2 Comments

@Ben: you can add also the password type, thus you'll have a password field.


Sep 29, 2009 at 2:42 PM // reply »
1 Comments

More data:

http://ajaxian.com/archives/html5-features-in-latest-iphone-application-cache-and-database

that's usefull thanks


Sep 30, 2009 at 10:24 AM // reply »
8 Comments

Hi Ben,
This might be a silly question, but, do you work with iPhone apps? Or was this just a personal interest because you might have one?


Sep 30, 2009 at 11:13 AM // reply »
6,516 Comments

@Jillian,

Yes, I do work on iPhone applications.


Oct 1, 2009 at 6:23 PM // reply »
1 Comments

Very cool I always like apps that switch the keyboard were it makes since
@Ray the db stuff is way cool. There are some libraries that let you write code that will work in air, safari, google gears and fall back to flash or cookie local storage also. So write once and run on many platforms. Google uses the local storage for Gmail is safari on the iPhone. Check out setting for safari to see what site are using storage.

@Ben you should update the contact form on your blog with the new field types.


Oct 5, 2009 at 4:56 AM // reply »
2 Comments

Really cool !!

So is it possible to have both types password and number ?

Something like :
<input type="password" type="number" name="n1" />

Thanks


Oct 5, 2009 at 7:50 AM // reply »
6,516 Comments

@Drake,

I am not sure about that. I think you can only specify one type at a time.


Oct 5, 2009 at 9:26 AM // reply »
2 Comments

Hi Ben,

Thanks for answering!

I was wondering about that because Dorinake said somehing like that in a previous post, but I can't test it right now. I'll let you know asap if it's possible.


Oct 13, 2009 at 7:21 PM // reply »
1 Comments

I found one more0 type="tel" will give you the alphanumeric keypad!

http://potch.me/iphone


Oct 15, 2009 at 8:23 AM // reply »
6,516 Comments

@Potch,

Ahh, nice!


Nic
Oct 29, 2009 at 1:58 AM // reply »
1 Comments

What generation/firmware version do you need? Your example code doesn't work on mine.


Oct 31, 2009 at 1:57 PM // reply »
6,516 Comments

@Nic,

I'm rocking out version 3.1 (7C144) according to my General settings.


Nov 5, 2009 at 9:15 AM // reply »
2 Comments

Hi, is it possible to change input type in ASP page? I tried to do this in Javascript after page load, but Iphone seems to ignore my change.


Nov 5, 2009 at 9:16 AM // reply »
6,516 Comments

@gorczas,

I am not sure that you can change input types at runtime? I have never tried that.


Nov 6, 2009 at 11:55 AM // reply »
2 Comments

I tried and according to Firebug I succeced, but IPhone didn't notice the change :/


Nov 6, 2009 at 12:04 PM // reply »
6,516 Comments

@Gorczas,

Gotcha. Still, I would try to avoid switching types at runtime.


Nov 14, 2009 at 3:43 PM // reply »
1 Comments

Hi,

first of all thanks for the help from you guys

I have doubt
does file upload works in iphone browser , i found type file as disabled , any method to upload file from a web app


Nov 15, 2009 at 3:38 PM // reply »
2 Comments

Hi guys,

Well, Apple has issued an updated doc for that on 2009-09-24...

Within this doc, you will find all keyboard types, viewport tricks, how to disable auto-correction and auto-capitalization on html fields and more....

http://developer.apple.com/safari/library/codinghowtos/mobile/userexperience/index.html

Hope this helps !

Ps: This works only for iPhone OS 3.1.x and later. ;)

Cheers!


Nov 15, 2009 at 6:51 PM // reply »
6,516 Comments

@Ygor,

Awesome, thanks!


Nov 15, 2009 at 6:59 PM // reply »
6,516 Comments

@Thomas,

I don't think you can upload files since the iPhone doesn't have a file system in the traditional sense.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 20, 2009 at 11:32 PM
Five Months Without Hungarian Notation And I'm Loving It
I've used headless camel case for years for not only ColdFusion variables, but also SQL tables and fields... pretty much everything involving code. I also subscribe to the "don't abbreviate and clea ... read »
Nov 20, 2009 at 11:00 PM
Five Months Without Hungarian Notation And I'm Loving It
@Marcel, Yeah, I always err on the side of longer but more readable variable names. As for the camel casing of CF methods and the headless camel casing of custom items, I get around this by always ... read »
Nov 20, 2009 at 10:56 PM
Five Months Without Hungarian Notation And I'm Loving It
I use the following and love it: my.namespace.MyComponents.functionMethodsOrUDF() CONSTANT_VALUES_OR_PROPERTIES One thing I always try is to CamelCaseBuiltInColdFusionFunctions() so others can tell ... read »
Nov 20, 2009 at 5:38 PM
Learning ColdFusion 8: CFImage Part I - Reading And Writing Images
Hi Ben, Great article. I've been looking around to see if ColdFusion image engine can programatically create the following "wrap around" effect: http://www.creativepro.com/article/photoshop-s-she ... read »
Nov 20, 2009 at 5:35 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Dave: I talked to Gert he suggested: <cfhttp method="get" url="http://{some cf website}" result="stuff" addtoken="yes" /> Note the addition of cfhttp attribute addtoken. That should persist y ... read »
Nov 20, 2009 at 5:23 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, Ahh, gotcha, yeah that makes sense. ... read »
Nov 20, 2009 at 5:17 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Ben, sorry if I didn't make this clear. You can make it work like that if you want, just put <cfset session.foo = 1> (and <cfset application.foo = 1>) in your OnRequestStart() and it reve ... read »