HTML <input> typ Atribut
Příklad
HTML formulář se dvěma vstupními poli; jedno textové pole a jedno tlačítko pro odeslání:
<form action="/action_page.php">
<label for="username">Username: </label>
<input type="text"
id="username" name="username"><br>
<input type="submit" value="Submit">
</form>
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
Atribut type
určuje typ
<input>
prvku, který se má zobrazit.
Pokud type
atribut není zadán, výchozí typ je "text".
Podpora prohlížeče
Attribute | |||||
---|---|---|---|---|---|
type | Yes | Yes | Yes | Yes | Yes |
Syntax
<input type="value">
Hodnoty atributů
Value | Description |
---|---|
button | Defines a clickable button (mostly used with a JavaScript to activate a script) |
checkbox | Defines a checkbox |
color | Defines a color picker |
date | Defines a date control (year, month, day (no time)) |
datetime-local | Defines a date and time control (year, month, day, time (no timezone) |
Defines a field for an e-mail address | |
file | Defines a file-select field and a "Browse" button (for file uploads) |
hidden | Defines a hidden input field |
image | Defines an image as the submit button |
month | Defines a month and year control (no timezone) |
number | Defines a field for entering a number |
password | Defines a password field |
radio | Defines a radio button |
range | Defines a range control (like a slider control) |
reset | Defines a reset button |
search | Defines a text field for entering a search string |
submit | Defines a submit button |
tel | Defines a field for entering a telephone number |
text | Default. Defines a single-line text field |
time | Defines a control for entering a time (no timezone) |
url | Defines a field for entering a URL |
week | Defines a week and year control (no timezone) |
Další příklady
Typ vstupu: tlačítko
Tlačítko, které po kliknutí aktivuje JavaScript:
<input type="button" value="Click me" onclick="msg()">
Typ vstupu: zaškrtávací políčko
Zaškrtávací políčka umožňují uživateli vybrat jednu nebo více možností z omezeného počtu možností:
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox"
id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br>
Typ vstupu: barva
Vyberte barvu z výběru barvy:
<label for="favcolor">Select your favorite color:</label>
<input type="color"
id="favcolor" name="favcolor">
Typ vstupu: datum
Definujte ovládací prvek data:
<label for="birthday">Birthday:</label>
<input type="date"
id="birthday" name="birthday">
Typ vstupu: datetime-local
Definujte ovládání data a času (bez časového pásma):
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local"
id="birthdaytime" name="birthdaytime">
Typ vstupu: email
Definujte pole pro e-mailovou adresu (bude automaticky ověřeno při odeslání):
<label for="email">Enter your email:</label>
<input type="email"
id="email" name="email">
Typ vstupu: soubor
Definujte pole pro výběr souboru a tlačítko „Procházet...“ (pro nahrávání souborů):
<label for="myfile">Select a file:</label>
<input type="file"
id="myfile" name="myfile">
Typ vstupu: skrytý
Definujte skryté pole (neviditelné pro uživatele).
Skryté pole často ukládá záznam databáze, který je třeba aktualizovat při odeslání formuláře:
<input type="hidden" id="custId" name="custId" value="3487">
Typ vstupu: obrázek
Definujte obrázek jako tlačítko pro odeslání:
<input type="image" src="img_submit.gif" alt="Submit">
Typ vstupu: měsíc
Definujte kontrolu měsíce a roku (bez časového pásma):
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month"
id="bdaymonth" name="bdaymonth">
Typ vstupu: číslo
Definujte pole pro zadání čísla (Můžete také nastavit omezení, jaká čísla jsou přijímána):
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number"
id="quantity" name="quantity" min="1" max="5">
K určení omezení použijte následující atributy:
- max - určuje maximální povolenou hodnotu
- min - určuje minimální povolenou hodnotu
- krok - určuje zákonné intervaly čísel
- hodnota – Určuje výchozí hodnotu
Typ vstupu: heslo
Definujte pole pro heslo (znaky jsou maskované):
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd">
Typ vstupu: rádio
Přepínače umožňují uživateli vybrat pouze jednu z omezeného počtu možností:
<input type="radio" id="html" name="fav_language" value="HTML">
<label
for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language"
value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript"
name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label>
Typ vstupu: rozsah
Definujte ovládací prvek pro zadání čísla, jehož přesná hodnota není důležitá (jako ovládací prvek posuvníku). Výchozí rozsah je 0 až 100. Můžete však nastavit omezení na přijatá čísla pomocí atributů min, max a krok:
<label for="vol">Volume (between 0 and 50):</label>
<input type="range"
id="vol" name="vol" min="0" max="50">
K určení omezení použijte následující atributy:
- max - určuje maximální povolenou hodnotu
- min - určuje minimální povolenou hodnotu
- krok - určuje zákonné intervaly čísel
- hodnota – Určuje výchozí hodnotu
Typ vstupu: reset
Definujte tlačítko reset (resetuje všechny hodnoty formuláře na výchozí hodnoty):
<input type="reset">
Tip: Tlačítko reset používejte opatrně! Může to být nepříjemné pro uživatele, kteří omylem aktivují resetovací tlačítko.
Typ vstupu: vyhledávání
Definujte vyhledávací pole (například vyhledávání na webu nebo vyhledávání Google):
<label for="gsearch">Search Google:</label>
<input type="search"
id="gsearch" name="gsearch">
Typ vstupu: odeslat
Definujte tlačítko pro odeslání:
<input type="submit">
Typ vstupu: tel
Definujte pole pro zadání telefonního čísla:
<label for="phone">Enter your phone number:</label>
<input type="tel"
id="phone" name="phone"
pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
Typ vstupu: text
Definujte dvě jednořádková textová pole, do kterých může uživatel zadávat text:
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label>
<input type="text"
id="lname" name="lname"><br>
Typ vstupu: čas
Definujte ovládací prvek pro zadání času (bez časového pásma):
<label for="appt">Select a time:</label>
<input type="time"
id="appt" name="appt">
Typ vstupu: url
Definujte pole pro zadání adresy URL:
<label for="homepage">Add your homepage:</label>
<input type="url"
id="homepage" name="homepage">
Tip: Safari na iPhone rozpozná typ zadávání adresy URL a změní klávesnici na obrazovce tak, aby mu odpovídala (přidá možnost .com).
Typ vstupu: týden
Definujte kontrolu týdne a roku (bez časového pásma):
<label for="week">Select a week:</label>
<input type="week"
id="week" name="week">
❮ HTML tag <input>