Тег INPUT, атрибут value

HTML Input Attributes

This chapter describes the different attributes for the HTML element.

The value Attribute

The input value attribute specifies an initial value for an input field:

Example

Input fields with initial (default) values:

The readonly Attribute

The input readonly attribute specifies that an input field is read-only.

A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).

The value of a read-only input field will be sent when submitting the form!

Example

The disabled Attribute

The input disabled attribute specifies that an input field should be disabled.

A disabled input field is unusable and un-clickable.

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

Example

The size Attribute

The input size attribute specifies the visible width, in characters, of an input field.

The default value for size is 20.

Note: The size attribute works with the following input types: text, search, tel, url, email, and password.

Example

Set a width for an input field:

The maxlength Attribute

The input maxlength attribute specifies the maximum number of characters allowed in an input field.

Note: When a maxlength is set, the input field will not accept more than the specified number of characters. However, this attribute does not provide any feedback. So, if you want to alert the user, you must write JavaScript code.

Example

Set a maximum length for an input field:

The min and max Attributes

The input min and max attributes specify the minimum and maximum values for an input field.

The min and max attributes work with the following input types: number, range, date, datetime-local, month, time and week.

Tip: Use the max and min attributes together to create a range of legal values.

Example

Set a max date, a min date, and a range of legal values:

The multiple Attribute

The input multiple attribute specifies that the user is allowed to enter more than one value in an input field.

The multiple attribute works with the following input types: email, and file.

Example

A file upload field that accepts multiple values:

The pattern Attribute

The input pattern attribute specifies a regular expression that the input field’s value is checked against, when the form is submitted.

The pattern attribute works with the following input types: text, date, search, url, tel, email, and password.

Tip: Use the global title attribute to describe the pattern to help the user.

Tip: Learn more about regular expressions in our JavaScript tutorial.

Example

An input field that can contain only three letters (no numbers or special characters):

The placeholder Attribute

The input placeholder attribute specifies a short hint that describes the expected value of an input field (a sample value or a short description of the expected format).

The short hint is displayed in the input field before the user enters a value.

The placeholder attribute works with the following input types: text, search, url, tel, email, and password.

Example

An input field with a placeholder text:

The required Attribute

The input required attribute specifies that an input field must be filled out before submitting the form.

The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.

Example

The step Attribute

The input step attribute specifies the legal number intervals for an input field.

Example: if step=»3″, legal numbers could be -3, 0, 3, 6, etc.

Tip: This attribute can be used together with the max and min attributes to create a range of legal values.

The step attribute works with the following input types: number, range, date, datetime-local, month, time and week.

Example

An input field with a specified legal number intervals:

Note: Input restrictions are not foolproof, and JavaScript provides many ways to add illegal input. To safely restrict input, it must also be checked by the receiver (the server)!

The autofocus Attribute

The input autofocus attribute specifies that an input field should automatically get focus when the page loads.

Example

Let the «First name» input field automatically get focus when the page loads:

The height and width Attributes

The input height and width attributes specify the height and width of an element.

Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded. Without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the images load).

Example

Define an image as the submit button, with height and width attributes:

The list Attribute

The input list attribute refers to a element that contains pre-defined options for an element.

Example

An element with pre-defined values in a :

The autocomplete Attribute

The input autocomplete attribute specifies whether a form or an input field should have autocomplete on or off.

Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.

The autocomplete attribute works with and the following types: text, search, url, tel, email, password, datepickers, range, and color.

Example

An HTML form with autocomplete on, and off for one input field:

Tip: In some browsers you may need to activate an autocomplete function for this to work (Look under «Preferences» in the browser’s menu).

HTML Exercises

HTML Form and Input Elements

For a complete list of all available HTML tags, visit our HTML Tag Reference.

Источник

Атрибут value

Определяет значение элемента формы, которое будет отправлено на сервер или получено с помощью клиентских скриптов. На сервер отправляется пара «имя=значение», где имя задается атрибутом name тега , а значение — атрибутом value .

В зависимости от типа элемента атрибут value выступает в следующей роли:

  • для кнопок ( input type=»button | reset | submit» ) устанавливает текстовую надпись на них;
  • для текстовых полей ( input type=»password | text» ) указывает предварительно введенную строку. Пользователь может стирать текст и вводить свои символы, но при использовании в форме кнопки Reset пользовательский текст очищается и восстанавливается введенный в атрибуте value ;
  • для флажков и переключателей ( input type=»checkbox | radio» ) уникально определяет каждый элемент, с тем, чтобы клиентская или серверная программа могла однозначно установить, какой пункт выбрал пользователь.
  • для файлового поля ( input type=»file» ) не оказывает влияние.

Синтаксис

Применяется

Значения

Значение по умолчанию

       

Как по вашему мнению расшифровывается аббревиатура "ОС"?

Офицерский состав Операционная система Большой полосатый мух

Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.

Типы тегов

HTML5

Блочные элементы

Строчные элементы

Универсальные элементы

Нестандартные теги

Осуждаемые теги

Видео

Документ

Звук

Изображения

Объекты

Скрипты

Списки

Ссылки

Таблицы

Текст

Форматирование

Формы

Фреймы

Источник

HTML Tag

An HTML form with three input fields; two text fields and one submit button:

Definition and Usage

The tag specifies an input field where the user can enter data.

The element is the most important form element.

The element can be displayed in several ways, depending on the type attribute.

The different input types are as follows:

Look at the type attribute to see examples for each input type!

Tips and Notes

Browser Support

Attributes

Attribute Value Description
accept file_extension
audio/*
video/*
image/*
media_type
Specifies a filter for what file types the user can pick from the file input dialog box (only for type=»file»)
alt text Specifies an alternate text for images (only for type=»image»)
autocomplete on
off
Specifies whether an element should have autocomplete enabled
autofocus autofocus Specifies that an element should automatically get focus when the page loads
checked checked Specifies that an element should be pre-selected when the page loads (for type=»checkbox» or type=»radio»)
dirname inputname.dir Specifies that the text direction will be submitted
disabled disabled Specifies that an element should be disabled
form form_id Specifies the form the element belongs to
formaction URL Specifies the URL of the file that will process the input control when the form is submitted (for type=»submit» and type=»image»)
formenctype application/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form-data should be encoded when submitting it to the server (for type=»submit» and type=»image»)
formmethod get
post
Defines the HTTP method for sending data to the action URL (for type=»submit» and type=»image»)
formnovalidate formnovalidate Defines that form elements should not be validated when submitted
formtarget _blank
_self
_parent
_top
framename
Specifies where to display the response that is received after submitting the form (for type=»submit» and type=»image»)
height pixels Specifies the height of an element (only for type=»image»)
list datalist_id Refers to a element that contains pre-defined options for an element
max number
date
Specifies the maximum value for an element
maxlength number Specifies the maximum number of characters allowed in an element
min number
date
Specifies a minimum value for an element
minlength number Specifies the minimum number of characters required in an element
multiple multiple Specifies that a user can enter more than one value in an element
name text Specifies the name of an element
pattern regexp Specifies a regular expression that an element’s value is checked against
placeholder text Specifies a short hint that describes the expected value of an element
readonly readonly Specifies that an input field is read-only
required required Specifies that an input field must be filled out before submitting the form
size number Specifies the width, in characters, of an element
src URL Specifies the URL of the image to use as a submit button (only for type=»image»)
step number
any
Specifies the interval between legal numbers in an input field
type button
checkbox
color
date
datetime-local
email
file
hidden
image
month
number
password
radio
range
reset
search
submit
tel
text
time
url
week
Specifies the type element to display
value text Specifies the value of an element
width pixels Specifies the width of an element (only for type=»image»)

Global Attributes

Event Attributes

  • Input Button Object
  • Input Checkbox Object
  • Input Color Object
  • Input Date Object
  • Input Datetime Object
  • Input DatetimeLocal Object
  • Input Email Object
  • Input FileUpload Object
  • Input Hidden Object
  • Input Image Object
  • Input Month Object
  • Input Number Object
  • Input Password Object
  • Input Range Object
  • Input Radio Object
  • Input Reset Object
  • Input Search Object
  • Input Submit Object
  • Input Text Object
  • Input Time Object
  • Input URL Object
  • Input Week Object

Источник

Читайте также:  Document write in html code
Оцените статью