एचटीएमएल इनपुट प्रकार
यह अध्याय HTML <input>
तत्व के विभिन्न प्रकारों का वर्णन करता है।
एचटीएमएल इनपुट प्रकार
यहां विभिन्न इनपुट प्रकार दिए गए हैं जिनका आप HTML में उपयोग कर सकते हैं:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
युक्ति: विशेषता का डिफ़ॉल्ट मान type
"पाठ" है।
इनपुट प्रकार टेक्स्ट
<input type="text">
एकल-पंक्ति पाठ इनपुट फ़ील्ड को परिभाषित करता है :
उदाहरण
<form>
<label for="fname">First name:</label><br>
<input
type="text" id="fname" name="fname"><br>
<label for="lname">Last
name:</label><br>
<input type="text" id="lname" name="lname">
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
पहला नाम:अंतिम नाम:
इनपुट प्रकार पासवर्ड
<input type="password">
पासवर्ड फ़ील्ड को परिभाषित करता है :
उदाहरण
<form>
<label for="username">Username:</label><br>
<input type="text"
id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
उपयोगकर्ता नाम:कुंजिका:
पासवर्ड फ़ील्ड में वर्ण नकाबपोश होते हैं (तारांकन या मंडलियों के रूप में दिखाए जाते हैं)।
इनपुट प्रकार सबमिट करें
<input type="submit">
फॉर्म-हैंडलर को फॉर्म डेटा
सबमिट करने के लिए एक बटन को परिभाषित करता है ।
फॉर्म-हैंडलर आमतौर पर एक सर्वर पेज होता है जिसमें इनपुट डेटा को प्रोसेस करने के लिए एक स्क्रिप्ट होती है।
फॉर्म-हैंडलर फॉर्म की action
विशेषता में निर्दिष्ट है:
उदाहरण
<form action="/action_page.php">
<label for="fname">First
name:</label><br>
<input type="text" id="fname" name="fname"
value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
अगर आप सबमिट बटन की value विशेषता को छोड़ देते हैं, तो बटन को एक डिफ़ॉल्ट टेक्स्ट मिलेगा:
उदाहरण
<form action="/action_page.php">
<label for="fname">First
name:</label><br>
<input type="text" id="fname" name="fname"
value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit">
</form>
इनपुट प्रकार रीसेट
<input type="reset">
एक रीसेट बटन को परिभाषित करता है
जो सभी फॉर्म मानों को उनके डिफ़ॉल्ट मानों पर रीसेट कर देगा:
उदाहरण
<form action="/action_page.php">
<label for="fname">First
name:</label><br>
<input type="text" id="fname" name="fname"
value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
यदि आप इनपुट मान बदलते हैं और फिर "रीसेट" बटन पर क्लिक करते हैं, तो फॉर्म-डेटा डिफ़ॉल्ट मानों पर रीसेट हो जाएगा।
इनपुट प्रकार रेडियो
<input type="radio">
एक रेडियो बटन को परिभाषित करता है ।
रेडियो बटन उपयोगकर्ता को सीमित विकल्पों में से केवल एक का चयन करने देते हैं:
उदाहरण
<p>Choose your favorite Web language:</p>
<form>
<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>
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
इनपुट प्रकार चेकबॉक्स
<input type="checkbox">
चेकबॉक्स को परिभाषित करता है ।
चेकबॉक्स उपयोगकर्ता को सीमित संख्या में विकल्पों में से शून्य या अधिक विकल्प चुनने देता है।
उदाहरण
<form>
<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>
</form>
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
इनपुट प्रकार बटन
<input type="button">
एक बटन परिभाषित करता है :
उदाहरण
<input type="button" onclick="alert('Hello World!')" value="Click Me!">
ब्राउज़र में उपरोक्त HTML कोड इस प्रकार प्रदर्शित होगा:
इनपुट प्रकार रंग
इनपुट फ़ील्ड के <input type="color">
लिए उपयोग किया जाता है जिसमें एक रंग होना चाहिए।
ब्राउज़र समर्थन के आधार पर, एक रंग बीनने वाला इनपुट फ़ील्ड में दिखाई दे सकता है।
उदाहरण
<form>
<label for="favcolor">Select your favorite
color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>
इनपुट प्रकार दिनांक
इनपुट फ़ील्ड के <input type="date">
लिए उपयोग किया जाता है जिसमें एक तिथि होनी चाहिए।
ब्राउज़र समर्थन के आधार पर, एक तिथि पिकर इनपुट क्षेत्र में दिखाई दे सकता है।
उदाहरण
<form>
<label for="birthday">Birthday:</label>
<input
type="date" id="birthday" name="birthday">
</form>
आप तिथियों पर प्रतिबंध जोड़ने के लिए min
और विशेषताओं का भी उपयोग कर सकते हैं :max
उदाहरण
<form>
<label for="datemax">Enter a date before
1980-01-01:</label>
<input type="date" id="datemax" name="datemax"
max="1979-12-31"><br><br>
<label for="datemin">Enter a date after
2000-01-01:</label>
<input type="date" id="datemin" name="datemin"
min="2000-01-02">
</form>
इनपुट प्रकार डेटाटाइम-स्थानीय
<input type="datetime-local">
कोई समय क्षेत्र के बिना दिनांक और समय इनपुट फ़ील्ड निर्दिष्ट करता है ।
ब्राउज़र समर्थन के आधार पर, एक तिथि पिकर इनपुट क्षेत्र में दिखाई दे सकता है।
उदाहरण
<form>
<label for="birthdaytime">Birthday (date and
time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
</form>
इनपुट प्रकार ईमेल
इनपुट फ़ील्ड के <input type="email">
लिए उपयोग किया जाता है जिसमें एक ई-मेल पता होना चाहिए।
ब्राउज़र समर्थन के आधार पर, सबमिट किए जाने पर ई-मेल पता स्वचालित रूप से मान्य किया जा सकता है।
कुछ स्मार्टफोन ईमेल प्रकार को पहचानते हैं, और ईमेल इनपुट से मेल खाने के लिए कीबोर्ड में ".com" जोड़ते हैं।
उदाहरण
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
इनपुट प्रकार फ़ाइल
<input type="file">
फ़ाइल-चयन फ़ील्ड और फ़ाइल अपलोड के लिए "ब्राउज़ करें" बटन को परिभाषित करता है ।
उदाहरण
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>
इनपुट प्रकार छिपा हुआ
एक छिपे हुए इनपुट फ़ील्ड को <input type="hidden">
परिभाषित करता है (उपयोगकर्ता के लिए दृश्यमान नहीं)।
एक छिपा हुआ फ़ील्ड वेब डेवलपर्स को डेटा शामिल करने देता है जिसे उपयोगकर्ताओं द्वारा प्रपत्र सबमिट किए जाने पर देखा या संशोधित नहीं किया जा सकता है।
एक छिपा हुआ फ़ील्ड अक्सर कौन सा डेटाबेस रिकॉर्ड संग्रहीत करता है जिसे प्रपत्र सबमिट करते समय अद्यतन करने की आवश्यकता होती है।
नोट: जबकि मान पृष्ठ की सामग्री में उपयोगकर्ता को प्रदर्शित नहीं किया जाता है, यह किसी भी ब्राउज़र के डेवलपर टूल या "स्रोत देखें" कार्यक्षमता का उपयोग करके दृश्यमान (और संपादित किया जा सकता है) है। सुरक्षा के रूप में छिपे हुए इनपुट का उपयोग न करें!
उदाहरण
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input
type="hidden" id="custId" name="custId" value="3487">
<input
type="submit" value="Submit">
</form>
इनपुट प्रकार महीना
<input type="month">
उपयोगकर्ता को एक महीने और वर्ष का चयन करने की अनुमति देता है।
ब्राउज़र समर्थन के आधार पर, एक तिथि पिकर इनपुट क्षेत्र में दिखाई दे सकता है।
उदाहरण
<form>
<label for="bdaymonth">Birthday (month and
year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>
इनपुट प्रकार संख्या
एक संख्यात्मक इनपुट फ़ील्ड को <input type="number">
परिभाषित करता है ।
You can also set restrictions on what numbers are accepted.
The following example displays a numeric input field, where you can enter a value from 1 to 5:
Example
<form>
<label for="quantity">Quantity (between 1 and
5):</label>
<input type="number" id="quantity" name="quantity"
min="1" max="5">
</form>
Input Restrictions
Here is a list of some common input restrictions:
Attribute | Description |
---|---|
checked | Specifies that an input field should be pre-selected when the page loads (for type="checkbox" or type="radio") |
disabled | Specifies that an input field should be disabled |
max | Specifies the maximum value for an input field |
maxlength | Specifies the maximum number of character for an input field |
min | Specifies the minimum value for an input field |
pattern | Specifies a regular expression to check the input value against |
readonly | Specifies that an input field is read only (cannot be changed) |
required | Specifies that an input field is required (must be filled out) |
size | Specifies the width (in characters) of an input field |
step | Specifies the legal number intervals for an input field |
value | Specifies the default value for an input field |
You will learn more about input restrictions in the next chapter.
The following example displays a numeric input field, where you can enter a value from 0 to 100, in steps of 10. The default value is 30:
Example
<form>
<label for="quantity">Quantity:</label>
<input
type="number" id="quantity" name="quantity" min="0" max="100" step="10"
value="30">
</form>
Input Type Range
The <input type="range">
defines a control for entering a number whose exact value is not important (like a slider control). Default
range is 0 to 100. However, you can set restrictions on what
numbers are accepted with the min
, max
, and step
attributes:
Example
<form>
<label for="vol">Volume (between 0 and 50):</label>
<input type="range" id="vol" name="vol" min="0" max="50">
</form>
Input Type Search
The <input type="search">
is used for search fields (a search field behaves like a regular text field).
Example
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>
Input Type Tel
The <input type="tel">
is used for input fields that should contain a telephone number.
Example
<form>
<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}">
</form>
Input Type Time
The <input type="time">
allows the user to select a time (no time zone).
Depending on browser support, a time picker can show up in the input field.
Example
<form>
<label for="appt">Select a time:</label>
<input type="time" id="appt" name="appt">
</form>
Input Type Url
The <input type="url">
is used for input fields that should contain a URL address.
Depending on browser support, the url field can be automatically validated when submitted.
Some smartphones recognize the url type, and adds ".com" to the keyboard to match url input.
Example
<form>
<label for="homepage">Add your homepage:</label>
<input type="url" id="homepage" name="homepage">
</form>
Input Type Week
The <input type="week">
allows the user to select a week and year.
Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="week">Select a week:</label>
<input type="week" id="week" name="week">
</form>
HTML Exercises
HTML Input Type Attribute
Tag | Description |
---|---|
<input type=""> | Specifies the input type to display |