Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input's "for" attribute not redirecting to input box

Tags:

html

I have a weird html problem.

I have a code like:

<label for="username">Username</label>
<input name="username" type="text"/>

But when I click on the label text Username I am not "redirected" into the input text field. By redirection I mean that the blinking cursor appears inside the input field and I can start writing.

What am I doing wrong?

like image 527
Derfder Avatar asked Jun 13 '12 05:06

Derfder


People also ask

Which attribute prevents the data entered into a field from being submitted with the form?

The disabled Attribute The value of a disabled input field will not be sent when submitting the form!

Which attribute is used to make an input field required?

The required attribute is a boolean attribute. When present, it specifies that an input field must be filled out before submitting the form. Note: The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.

Which attribute is not a part of the input tag?

1. Which of the following is not a type of attribute for input tag? Explanation: Day is not defined in the pre-defined attribute list of input tag. Week attribute defines week and year when used as attribute in input tag.

Which of the following attribute is used to avoid showing suggestions in an input control?

The autocomplete attribute is used to enable and disable autocompletion of text. This attribute contains two values: on. off.


2 Answers

For in label refers to an id:

<label for="username">Username</label>
<input name="username" id="username" type="text"/>

More: http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1

like image 192
Fab V. Avatar answered Oct 03 '22 07:10

Fab V.


The text box also needs a value for id, so use one in the text box like this:

<input name="username" id="username" type="text"/>
like image 44
Sudip Pal Avatar answered Oct 03 '22 06:10

Sudip Pal