0% found this document useful (0 votes)
15 views

Lecture 3 - Forms

Lecture 3 - Forms

Uploaded by

ochanrogermila
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture 3 - Forms

Lecture 3 - Forms

Uploaded by

ochanrogermila
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

HTML Forms

What is HTML <form>?


• <form> is an HTML element to collect input data or used to collect information from a user.
• The HTML <form> element is used to create an HTML form for user input
• It provides facilities to input text, number, values, email, password, and control fields such as checkboxes,
radio buttons, submit buttons, etc

Syntax: <form> <! -----form element> </form>

Form Attributes

No. Attribute Description


1. action Backend script ready to process your passed data.
2. method Method to be used to upload data. The most frequently used are GET and POST methods.
3. target Specify the target window or frame where the result of the script will be displayed. It takes
values like _blank, _self, _parent etc.
4. enctype to specify how the browser encodes the data before it sends it to the server.
application/x-www-form-urlencoded − This is the standard method most forms use in simple
scenarios.
mutlipart/form-data − This is used when you want to upload binary data in the form of files
like image, word file etc.
HTML Forms
Example:
<form action = "Script URL" method = "GET|POST">
form elements like input, textarea etc.

</form>

HTML Form Controls


There are different types of form controls that you can use to collect data using HTML form
• Text field input
• Textarea input
• Checkboxes Controls
• Radio Box Controls
• Select Box Controls
• File Select boxes
• Hidden Controls
• combobox
• Clickable Buttons (password)
• Submit and Reset Button
HTML Forms
Text field: This is a single line text input

Example:
<form>
First name: <input type = "text" name = "first_name" />
</form>

Output :

No. Attribute Description


1. Type Indicates the type of input control and for text input control it will be set to text.
2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
3. value This can be used to provide an initial value inside the control.
4. size Allows to specify the width of the text-input control in terms of characters.
5. maxlength Allows to specify the maximum number of characters a user can enter into the text box.
HTML Forms
Password : This is also a single-line text input but it masks the character as soon as a user enters it.

Example:
<form>
<input type = "text" name = "user_id" />
</form>

Output :

No. Attribute Description


1. Type Indicates the type of input control and for text input control it will be set to password.
2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
3. value This can be used to provide an initial value inside the control.
4. size Allows to specify the width of the text-input control in terms of characters.
5. maxlength Allows to specify the maximum number of characters a user can enter into the text box.
HTML Forms
TEXTAREA : This is used when the user is required to give details that may be longer than a single sentence or descriptions
Example:
<form>
<textarea rows = "5" cols = "50" name = "description">
</form>

Output :

No. Attribute Description


1. Type Indicates the type of input control and for text input control it will be set to password.
2. rows Indicates the number of rows of text area box.
3. cols Indicates the number of columns of text area box
HTML Forms
Checkbox Control: Checkboxes are used when more than one option is required to be selected.

Example:
<form>
<input type = "checkbox" name = "maths" value = "on"> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
</form>
Output :

No. Attribute Description


1. Type Indicates the type of input control and for text input control it will be set to checkbox.
2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
3. value This can be used to provide an initial value inside the control.
4. checked Set to checked if you want to select it by default.
HTML Forms
Radio Control: Radio buttons are used when out of many options, just one option is required to be selected.

Example:
<form>
<input type = "radio" name = "subject" value = "maths"> Maths
<input type = "radio" name = "subject" value = "physics"> Physics
</form>
Output :

No. Attribute Description


1. Type Indicates the type of input control and for text input control it will be set to radio.
2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
3. value This can be used to provide an initial value inside the control.
4. checked Set to checked if you want to select it by default.
HTML Forms
selectbox: Radio buttons are used when out of many options, just one option is required to be selected. A
select box, also called drop down box which provides option to list down various options in the form of drop
down list, from where a user can select one or more options.

Example: <form>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</form>

Output :

No. Attribute Description


2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
3. value This can be used to provide an initial value inside the control.
4. selected Specifies that this option should be the initially selected value when the page loads.
5. label An alternative way of labeling options
HTML Forms
File Upload Box: If you want to allow a user to upload a file to your web site, you will need to use a file
upload box

Example: <form>
<input type = "file" name = "fileupload" accept = "image/*" />
</form>
Output :

No. Attribute Description


2. name Used to give a name to the control which is sent to the server to be recognized and get the
value..
5. accept Specifies the types of files that the server accepts.
HTML Forms
Button Controls: There are various ways in HTML to create clickable buttons. You can also create a clickable
button using <input>tag by setting its type attribute to button.

Example: <form>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
<input type = "button" name = "ok" value = "OK" />
<input type = "image" name = "imagebutton" src = "/html/images/logo.png"

</form>

Output :

No. Attribute Description


1. submit This creates a button that automatically submits a form.
2. reset This creates a button that automatically resets form controls to their initial values.
3. button This creates a button that is used to trigger a client-side script when the user clicks that
button.
CLASS ASSIGMNENT
Class exercise 3 : Use HTML to design the form below
Send the HTML file created on my email
[email protected]

• Creativity is encouraged in your work


• Don’t use the same colours
• Add more form elements as you see fit.

Try any of the following Input types to learn the


output.

i. <input type="date">
ii. <input type="email">
iii. <input type="month">
iv. <input type="password">
v. <input type="search">
vi. <datalist>
vii. <fieldset>
viii. <label>

Submission deadline for class assignment: 30th /09/2024

You might also like