Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
📝 Days 6–10 – Forms, Semantics और SEO  ·  दिन 07

दिन 7: Forms 2: Select, Textarea और Validation

⏱ 90 min📶 Intermediate🎯 100% self-study
दिन 7 / 15

✅ आज आप सीखेंगे

  • select, option और optgroup से dropdowns
  • datalist से suggestions
  • textarea से कई lines का text
  • fieldset और legend से fields का group
  • Built-in validation: required, min/max, maxlength, pattern

🏢 असली दुनिया में

पिछले हफ़्ते के form से 40 enquiries आईं – पर 9 में mobile number ग़लत थे और 5 event की तारीख़ भूल गए। आज आप browser से ही ग़लत data भेजने से पहले रुकवाएँगे: JavaScript की ज़रूरत नहीं।

Dropdowns: select और option

HTML
<label for="occasion">Occasion</label>
<select id="occasion" name="occasion" required>
  <option value="">– Choose –</option>
  <optgroup label="Family">
    <option value="wedding">Wedding</option>
    <option value="birthday">Birthday</option>
  </optgroup>
  <optgroup label="Festivals">
    <option value="diwali" selected>Diwali</option>
    <option value="rakhi">Raksha Bandhan</option>
  </optgroup>
  <option value="corporate">Corporate gifting</option>
</select>
<br><br>
<label for="boxes">Box sizes (Ctrl/⌘ for many)</label><br>
<select id="boxes" name="boxes" multiple size="3">
  <option>250 g</option><option>500 g</option><option>1 kg</option>
</select>
▶  Result

datalist: लिखें या चुनें

HTML
<label for="city">Delivery city</label>
<input id="city" name="city" list="cities" placeholder="Start typing…">
<datalist id="cities">
  <option value="Jaipur"><option value="Ajmer"><option value="Kota"><option value="Udaipur"><option value="Jodhpur">
</datalist>
▶  Type “J”

लंबे text के लिए textarea

HTML
<label for="note">Special instructions</label><br>
<textarea id="note" name="note" rows="4" cols="40" maxlength="200"
  placeholder="e.g. less sugar, Jain (no onion-garlic) namkeen"></textarea>
▶  Result

fieldset और legend से grouping

HTML
<fieldset>
  <legend>Payment</legend>
  <label><input type="radio" name="pay" value="upi" checked> UPI</label>
  <label><input type="radio" name="pay" value="cash"> Cash on pickup</label>
</fieldset>
<fieldset disabled>
  <legend>Gift wrapping (coming soon)</legend>
  <label><input type="checkbox"> Add ribbon</label>
</fieldset>
▶  disabled on a fieldset disables everything inside

Built-in validation

Attributeनियमउदाहरण
requiredख़ाली नहीं होना चाहिए<input required>
min / maxNumber या date rangemin="5" max="200"
stepमान्य बढ़तstep="0.5"
minlength / maxlengthText की लंबाईminlength="3"
patternRegular expressionpattern="[6-9][0-9]{9}"
type="email" / "url"Format जाँचa@b.com
titlepattern error में hint की तरह दिखता हैtitle="10-digit mobile"
HTML
<form onsubmit="alert('All fields valid – would be sent!'); return false;">
  <p><label>Name* <input name="name" required minlength="3"></label></p>
  <p><label>Mobile* <input name="mobile" type="tel" required pattern="[6-9][0-9]{9}" title="10-digit Indian mobile starting with 6–9" placeholder="9829012345"></label></p>
  <p><label>PIN code <input name="pin" pattern="[1-9][0-9]{5}" title="6-digit PIN code"></label></p>
  <p><label>Quantity (kg)* <input name="qty" type="number" required min="5" max="200" step="0.5"></label></p>
  <p><label>Event date* <input name="date" type="date" required min="2026-01-01"></label></p>
  <button>Send enquiry</button>
</form>
▶  Try sending it empty, then with 12345 as mobile
🧠 Indian mobile pattern पढ़ना

[6-9][0-9]{9} = पहला अंक 6, 7, 8 या 9, फिर ठीक नौ और अंक। Pattern को पूरी value से मेल खाना चाहिए। PIN code: [1-9][0-9]{5}।

⚠️ Browser checks सुरक्षा नहीं हैं

कोई भी HTML validation bypass कर सकता है (DevTools, scripts)। यह user experience सुधारता है; server को फिर भी सब दोबारा validate करना होगा।

और काम के attributes

HTML
<form novalidate>
  <p><label>Order id <input value="BK-1042" readonly></label> (readonly – sent)</p>
  <p><label>Coupon <input value="DIWALI20" disabled></label> (disabled – NOT sent)</p>
  <p><label>Name <input name="n" autofocus autocomplete="name"></label></p>
  <p><label>OTP <input inputmode="numeric" autocomplete="one-time-code" maxlength="6"></label></p>
</form>
▶  novalidate on the form switches checks off (e.g. for “save draft”)

असली example: final enquiry form

HTML
<form action="https://httpbin.org/post" method="post" target="_blank">
  <fieldset>
    <legend>Your details</legend>
    <p><label for="n">Name*</label><br><input id="n" name="name" required minlength="3" autocomplete="name"></p>
    <p><label for="m">Mobile*</label><br><input id="m" name="mobile" type="tel" required pattern="[6-9][0-9]{9}" title="10-digit mobile" autocomplete="tel"></p>
  </fieldset>
  <fieldset>
    <legend>Order</legend>
    <p><label for="o">Occasion*</label><br>
      <select id="o" name="occasion" required><option value="">– Choose –</option><option>Wedding</option><option>Diwali</option><option>Corporate</option></select></p>
    <p><label for="q">Quantity (kg)*</label><br><input id="q" name="qty" type="number" min="5" max="200" step="0.5" required></p>
    <p><label for="d">Event date*</label><br><input id="d" name="event_date" type="date" required></p>
    <p><label for="t">Notes</label><br><textarea id="t" name="notes" rows="3" maxlength="300"></textarea></p>
  </fieldset>
  <p><label><input type="checkbox" name="consent" required> I agree to be contacted on WhatsApp</label></p>
  <button type="submit">Send enquiry</button>
</form>
▶  Complete, validated form

🏅 आज के Job Skills

✔ select, datalist और textarea fields बनाना✔ fieldset/legend से fields group करना✔ required, min/max, maxlength और pattern से validate✔ readonly, disabled, autocomplete और inputmode का इस्तेमाल

Practice tasks

🏋️ Practice – ख़ुद करें

Task 1: 1–5 rating (select), comment (textarea, 10–300 characters) और ज़रूरी e-mail वाला feedback form बनाएँ।
Solution देखें
HTML
<form onsubmit="alert('Thanks!'); return false;">
  <p><label>Rating <select name="rating" required><option value="">–</option><option>5</option><option>4</option><option>3</option><option>2</option><option>1</option></select></label></p>
  <p><label>Comment<br><textarea name="comment" minlength="10" maxlength="300" required rows="3"></textarea></label></p>
  <p><label>E-mail <input type="email" name="email" required></label></p>
  <button>Send</button>
</form>
▶  Result
Task 2: RJ14AB1234 जैसे Indian vehicle number का pattern लिखें।
Solution देखें
HTML
<input name="vehicle" pattern="[A-Z]{2}[0-9]{2}[A-Z]{1,2}[0-9]{4}" title="e.g. RJ14AB1234" placeholder="RJ14AB1234">
▶  Result
Task 3: Form submit होने पर readonly और disabled का अंतर समझाएँ।

Quick quiz

🧠 Quick Quiz – ख़ुद को जाँचें

1. कौन suggestions दिखाता है पर कोई भी text लेने देता है?
list="id" से जुड़ा।
2. pattern="[0-9]{6}" क्या स्वीकार करता है?
पूरी value मेल खाए।
3. Disabled field…
readonly fields भेजे जाते हैं।
4. क्या सुरक्षा के लिए सिर्फ़ HTML validation काफ़ी है?
इसे bypass किया जा सकता है।
5. legend किसे caption देता है?
हर field के साथ screen readers पढ़ते हैं।

Interview corner

💼 Interview Corner

Client-side vs server-side validation?

Client-side (HTML/JS) तुरंत feedback देता है और ग़लत requests घटाता है; server-side सुरक्षा और data की शुद्धता के लिए ज़रूरी है क्योंकि client checks bypass हो सकते हैं।

Form errors को accessible कैसे बनाते हैं?

Labels लें, नियम पहले बताएँ (aria-describedby), field के पास साफ़ text messages दिखाएँ, सिर्फ़ रंग पर निर्भर न रहें, और पहली error पर focus ले जाएँ।

सारांश

  • तय choices के लिए select/option/optgroup; suggestions के लिए datalist।
  • लंबे text के लिए textarea; group के लिए fieldset + legend।
  • required, min/max, step, minlength/maxlength, pattern browser में validate करते हैं।
  • Server पर हमेशा दोबारा validate करें।
➡️ आगे

Day 8: semantic HTML5 layout – header, nav, main, section, article, aside और footer।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

क्या browser का error message बदल सकते हैं?
हाँ, थोड़े JavaScript (setCustomValidity) से – JavaScript course में।
type="number" पर pattern क्यों नहीं चलता?
pattern सिर्फ़ text जैसे inputs (text, tel, email, url, search, password) पर लागू होता है। Numbers के लिए min/max/step लें।
← HTML (15 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicदिन 8: Semantic HTML5 Page Layout आपकी प्रगति: 7 / 15 (47%) · Lesson 8 / 15 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें