How to fix the broken iPad form label click issue
- Categories:
- JavaScript
- Tags:
- form, ipad, iphone, javascript, label
- Published:
- 7:33pm on Friday 20th August, 2010
I love my iPad. It’s almost perfect. If only I could click on form labels! Here is how I fixed that particular niggle with some judicious use of of JavaScript.
Updated 23/08: Created a jQuery version - see the bottom of this article for the code!
If, like me, you love some semantic HTML markup, it’s likely that your form elements—input, select, textarea—are marked up something like this:
<label for=“your_name”>Your name:</label> <input type=“text” id=“your_name” name=“your_name” size=“20” maxlength=“20”>
You might wrap the input inside the label, but the result is the same—clicking on the label will give focus to the text field so you can start typing (or select/check it in the case of radio buttons and checkboxes). If you’re particularly clever you might even be able to string together a relatively coherent sentence involving Fitt’s Law—but all that falls apart when it comes to Mobile Safari.
Labels in Mobile Safari
Mobile Safari, the browser found on iPhones, iPod Touches and the iPad, does not (currently) implement the same label behaviour as other browsers. Clicking on labels doesn’t do anything—possibly, as Ben Darlow suggests, it is because it would interfere with the tap-to-select-text functionality, although personally I think that usability trumps obscure text-selection use cases.
What’s even weirder is that, in over an hour of googling, I couldn’t find a single reference to this issue. Surely someone, somewhere must have noticed that clicking or tapping on labels in forms on iPad doesn’t select the input? I resolved that when I published a fix for the issue, it would include a couple of clunky sentences stuffed with as many keywords related to the tap click form label input select checkbox radio button problem as possible…
Enable iPad or iPhone users to activate your form elements when they tap on a label
Here is a simple script that does just that.
Very simply, it collects all the labels on the page, then loops through them and applies an onclick event (which the iPad triggers when you tap on an element). The event looks for a for attribute, figures out what sort of form element it relates to, and performs the correct action; either focusing on the element (text inputs, dropdowns and textareas) or toggling the selected state of checkboxes and radio buttons.
There is a test page here where you can try the script on your own iPhone or iPad. If you have an alternative method, or more efficient way to code it, please let me know in the comments. If someone wants to knock up a jQuery plugin as well, that would be nice, as I’ve forgotten how to do it…
As we only need to call the function for the affected platforms, just do something like this (using your document.ready event of choice):
if (navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/iPad/i)) {
iPadLabels.fix();
}
(And don’t forget that, if and when Apple fix this “bug”, to remove the script.)
jQuerified
And here’s a version of the code in jQuery instead - obviously you need to have the library loaded in your page as well.
Original photo by Phantomfies

I'd love to hear what you think - please use the form below to leave your comments. Anything I consider too offensive, off-topic, or spammy will be deleted at my discretion. Some HTML is permitted, or you can use Textile.
Jeremy Keith at 12:10pm on 21st August, 2010 #
trovster at 12:22pm on 21st August, 2010 #
Byron at 3:23pm on 25th August, 2010 #
Thomas Edwards at 11:26pm on 26th August, 2010 #
Igor at 6:21am on 23rd September, 2010 #
Ben Hull at 5:12am on 24th September, 2010 #
Andre at 7:57pm on 22nd October, 2010 #
Matthew Pennell at 6:37am on 23rd October, 2010 #
Andre at 3:05pm on 25th October, 2010 #
Colleen at 2:51am on 26th October, 2010 #
Colleen at 3:12am on 26th October, 2010 #
Matthew Pennell at 2:28pm on 26th October, 2010 #
hypest at 8:48pm on 28th October, 2010 #
hypest at 8:51pm on 28th October, 2010 #
Davide Molin at 10:23pm on 30th November, 2010 #
Davide Molin at 10:36pm on 30th November, 2010 #
Matthew Pennell at 6:51am on 1st December, 2010 #
Davide Molin at 7:52am on 1st December, 2010 #
Matthew Pennell at 8:43am on 1st December, 2010 #
Davide Molin at 9:16am on 1st December, 2010 #
albert at 4:05am on 5th December, 2010 #
Leonard Lin at 5:50am on 27th January, 2011 #
Trent Ahrens at 9:43pm on 23rd February, 2011 #
Emma at 3:16pm on 11th March, 2011 #
Vincent Young at 6:23pm on 14th September, 2011 #
jon at 7:50pm on 8th November, 2011 #
statinternet at 8:26am on 18th January, 2012 #
Bobby Marko at 4:21am on 20th January, 2012 #
Vincent Young at 4:45am on 20th January, 2012 #
Jason Chandler at 4:51pm on 20th January, 2012 #
Matthew Pennell at 6:49pm on 20th January, 2012 #
RaphaelDDL at 6:58pm on 25th January, 2012 #
Jan Van Lysebettens at 8:42am on 16th February, 2012 #
Jason at 6:57am on 23rd February, 2012 #
Josh at 4:12am on 10th March, 2012 #
Ramin at 3:42am on 19th March, 2012 #
richard at 8:39pm on 15th April, 2012 #
WebsiteInfo at 2:07pm on 5th May, 2012 #
Sarah at 6:56am on 12th May, 2012 #
Michael Mitschele at 5:13am on 15th May, 2012 #