Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label for File input in firefox

When I add a label the a form input, I can normally click the label and it will refer me to the appropriate input (see below).

<label for="input">Label</label><input type="text" id="input"/>

However, when I try to accomplish the same with a file input, the click on the label gets ignored. Is this a bug? A "feature"? And is there any way to still accomplish this?

jsFiddle testcase: here

like image 647
Exelian Avatar asked Sep 22 '11 14:09

Exelian


People also ask

How do you put a label inside input in HTML?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit). Think of an implicit label as hugging an input, and an explicit label as standing next to an input and holding its hand.

What is name in input tag?

The name attribute specifies the name of an <input> element. The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted. Note: Only form elements with a name attribute will have their values passed when submitting a form.


1 Answers

The label's prescribed behavior differs between HTML specifications.

More precisely, this is probably a bug in FF (rather than an extra feature in the others), because this behavior should usually be included according to the HTML 4 spec: When a LABEL element receives focus, it passes the focus on to its associated control. See the section below on access keys for examples.

The current HTML spec is more nuanced, but does indicate the possibility that it do nothing (this is the expected behavior in iOS).

like image 197
Eran Zimmerman Gonen Avatar answered Oct 21 '22 05:10

Eran Zimmerman Gonen