The purpose of form is to collect information from people, to know their opinion, skills, feedback, etc..
In previous post, we saw about all the input elements and it’s attributes.
This post will describes about form in HTML,<form> element, it’s attributes, other form elements, and sample form example.
What is form in HTML?
In world of web every website have forms like, log in form, registration form, contact form, feedback from.
HTML form collects data from user and store in database. Server process this data.
Most common information the html form contains are user_id, password, username,..etc.
The <form> element is used to create a form.
So first we discuss about the <form> tag and it’s attributes.
The <form> element
<form> attributes
- name
- action
- method
- target
- autocomplete
- enctype
- novalidate
(1) name
(2) action
(3) method
- Get method
- Post method
Difference between get and post methods
get
post
(4) target
(5) autocomplete
![]() |
Form autocomplete attribute |
In above output figure suggestion box is display when clicking on text field.
(6) enctype
- multipart/form data
- text/plain
- application/x-www-x-www-form-urlencoded
(7) novalidate
The HTML4 form elements
- <label>
- <input>(describes in previous post)
- <select> and <option>
- <textarea>
- <button>
- <fieldset> and <legend>
- <optgroup>
(1) <label>
![]() |
Output of label element |
(2) <select> and <option>
- The <select> element display drop-down list, to select an option from that list.
- The <option> element specify the list of multiple options.
- By default first option is selected.
- If you want other option already selected, specify selected attribute to that specific <option> element.
- You can also choose multiple options using multiple attribute.
![]() |
Output of <select> and <option> |
(3) <textarea>
![]() |
<textarea> element |
(4) <button>
![]() |
<button> element |
(5) <fieldset> and <legend>
![]() |
<fieldset> and <legend> element |
(6) <optgroup>
![]() |
<optgroup> element |
HTML 5 form elements
- <datalist>
- <keygen>
- <output>
<datalist>
Define <datalist> element under <input> element.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!Doctype html> <html> <head> <title>HTML5 attributes</title> </head> <body> <form name="f1" action="#"> <h1>Select your day:</h1> <!--datalist--> <input list="days"> <datalist id="days"> <option value="Sunday"> <option value="Monday"> <option value="Tuesday"> <option value="Wednesday"> <option value="Thursday"> <option value="Friday"> <option value="Saturday"> </datalist> </form> </body> </html> |
![]() |
HTML5 <datalist> element |
<keygen>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!Doctype html> <html> <head> <title>HTML5 attributes</title> </head> <body> <form name="f1" action="#"> <!--keygen--> Email_id:-<br> <input type="email" name="em"><br> Passwprd:-<br> <input type="password" name="pwd"><br> Data encrtyption<keygen name="encryptdata"> <input type="submit" value="Submit"> </form> </body> </html> |
Output:-
![]() |
HTML5 <keygen> element |
<output>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!Doctype html> <html> <head> <title>HTML5 attributes</title> <style> body{ background-color:#FF9878;} form{ background-color:#FF6A7B;} </style> </head> <body> <h2>Enter two number and dispaly summation.</h2> <form name="f1" action="#" oninput="sum.value=parseInt(no1.value)+parseInt(no2.value)"> No1: <input type="number" name="no1" value=""> No2: <input type="number" name="no2" value=""> SUM= <output name="sum"></output> </select> </form> </body> </html> |
Output:-
![]() |
HTML5 <output> element |
student data collector form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <!Doctype html> <html> <head> <title>Student data</title> <link rel="stylesheet" type="text/css" href="std.css"> </head> <body> <section> <form name="f1" target="#" method="post"> <h1>Student Record</h1> <fieldset> <legend>-:Personal Information:-</legend> <label for="fullnm">Full_name:</label><br> <input type="text" name="fullnm" id="fnm" placeholder="Enter your name"></br> <label for="bdt">Birthdate:</label><br> <input type="date" name="bdt" id="birth" min="1990-12-31" max="2000-12-31"></br> <label for="Age" >Age:</label><br> <input type="number" name="age" id="ag" min=5 max=12></br> <label for="gend">Gender:</label><br> <input type="radio" name="gend" id="gen" value="Male" checked>Male <input type="radio" name="gend" id="gen" value="Female">Female</br> <label for="addrs">Address:</label><br> <textarea name="addr" rows="5" cols="20"></textarea></br> <label for="phone">Contact no:</label><br> <input type="tel" name="phone" id="phno" pattern="[0-9]{5}-[0-9]{5}"> </fieldset> <h3>STUDENT PROFILE</h3> <label for="enroll">Enrollment no:</label><br> <input type="text" name="enroll" id="erno" required></br> <label for="std">Standard:</label> <select name="std" id="std"> <option value="1">1</option> <option value="1">2</option> <option value="1">3</option> <option value="1">4</option> <option value="1">5</option> <option value="1">6</option> <option value="1">7</option> <option value="1">8</option> <option value="1">9</option> <option value="1">10</option> </select> <label for"class">Class:</label> <select name="cls" id="cls"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> </select><br> <label for="sport">Sports activity:</label> <br><br> <input type="checkbox" name="cricket">Cricket <input type="checkbox" name="basketball">Basketball<br> <input type="checkbox" name="football" id="ftb">Football <input type="checkbox" name="Table tenis" id="tbl">Table tenis <br> <label for="attand" id="atd">Attandence:</label> <input type="radio" name="hundrd" id="attd" value="100%">100% <input type="radio" name="fifty" id="attd" value="80%">80% <input type="radio" name="gend" id="gen" value="50%">50% <input type="radio" name="gend" id="gen" value="30%">30%</br> <label for="grd" id="gr">Grade:</label> <input type="radio" name="grade" id="grd" value="First">First class <input type="radio" name="grade" id="grd" value="Second">Second class <input type="radio" name="grade" id="grd" value="Fail">Fail</br> <input type="submit" id="submt" value="Submit"> <input type="reset" name="rset" value="Reset"> </form> </section> </body> </html> |
CSS code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | section{ position:absolute; top:160px; left:160px; background:linear-gradient(black,silver,black); color:#ccf; border-radius:20px; margin:30px; padding:15px; font-size:16pt; box-shadow:5px 5px 7px black; } label{ margin:5px; padding-right:20px; width:300px; } input[type],select{ margin:20px 20px; padding:3px; height:30px; width:100; display:inline-block; border:2px solid gray; border-radius:10px; } textarea{ padding:3px; margin:20px 20px; height:60px; width:120; border:2px solid gray; border-radius:10px; } #submt,input[type=reset]{ width:100px; height:50px; background:radial-gradient(black,gray); color:#fcf; font-size:16pt; border:2px solid gold; } #sprt{ position:absolute; left:200px; top:1010px; } |
Output:-
![]() |
Student form |
0 Comments