Showing posts with label Creating Form in HTML. Show all posts
Showing posts with label Creating Form in HTML. Show all posts

CREATING FORM IN HTML

 The HTML form is the interface of a web page that facilitates the user to enter data (such as name, email id, phone number etc.) that is to be sent to the server for further processing. There are various form elements that help to design a form through textbox, radio buttons, drop down menus, checkboxes, password, list, combo box etc. while writing codes.

Every form must begin with a <FORM> tag, which can be typed inside the body tag of HTML document. Syntax to create HTML form is as follows : 

<HTML>

<HEAD>

<TITLE> Form Making</TITLE>

</HEAD>

<BODY>

<FORM>

Form elements

</FORM>

</BODY>

</HTML>

Form Element: In this section we will know about some form elements which are used to make a form.

Input Element:

Input Element is the main tag or element of form, used to make fields to input data from user. We can create different input fields to gather various kinds of information from a user. 

Syntax to use <INPUT> tag is as follows: 

<INPUT TYPE = "   "Name = "   "Value = "   "Align = "    "Size = "     ">

The input tag has the following attributes :

TYPE : It specifies the type of form element such as text, radio etc.

NAME : It is the name given to form element. This attribute is used to uniquely identify the element in the form. 

VALUE : It is used to specify the default value to the control element.

ALIGN : This attribute is used to align the attribute with respect to the form margins.

SIZE : This attribute specifies the horizontal size of the text box.

Adding a Text Box

A text box allows a user to enter data such as any character and number.

For example :

<HTML>

<HEAD>

<TITLE> Form </TITLE>

</HEAD>

<BODY>

<FORM>

FIRST NAME :

<INPUT Type = "TEXT" Name = "EName1" Size = "30" Value = "Enter First Name">

LAST NAME :

<INPUT Type = "TEXT" Name = "EName2" Size = "30" Value = "Enter Last Name">

</FORM>
</BODY>
</HTML>


Try it yourself editor
 
Code
Output

Adding a Radio Button : Radio buttons are used when the user has to make selection among multiple choices or options. It is generally used for selection of gender, Yes or No, True or False, etc. For example, for accepting the gender, the programmers need to specify two radio buttons "Male" and "Female", but not both. For example:
<INPUT Type = "Radio" Name = "Gender" Value = "Male" Checked> Male
<INPUT Type = "Radio" Name = "Gender" Value = "Female" > Female
Type = "Radio" indicates that the form element is radio button.
Name = "Gender" is the name of the radio button group.
Value = "Male" and Value = "Female" signifies that one radio button has value "Male and the other has the value "Female"
Checked attribute selects the specific radio button by default. Here "Male" radio button is checked by default.


Try it yourself editor
 
Code
Output

Adding a Check Box : A check box is like a toggle switch where a user can select the desired choice by clicking on the check box. 
Foe example :
<INPUT Type = "Checkbox" Name = "Hobbies" Value = "Reading" Checked> Reading.
Type = "Checkbox" indicates that the form element is Checkbox.
Name = "Hobbies" is the name of the checkbox group.
Value = "Reading" signifies that the checkbox is ticked. 
Checked attribute selects the specific checkbox button by default. 


Try it yourself editor
 
Code
Output

Adding a Password Field : This is also a single line text input but it masks the character as soon as a user enters into it. The password is not visible to the user in password field control. For example:
<INPUT Type = "Password" Name = "Salary" Size = "10">
password field isn't showing the characters entered

Combo Box : A combo box provides option to list down various options in the form of drop down list, from where a user can select desired option. <SELECT> Tag is used to start the combo box. It is a  container tag. <OPTION> Tag is used to create the combo drop down list. It is an empty tag.
For example :
<SELECT NAME="List Name">
<OPTION>Option1
<OPTION>Option2
</SELECT>



Try it yourself editor
 
Code
Output


Now Assignment and Activity related to this topic

Q. Create an HTML Form give below:

Ans. Type the HTML coding in text editor as follows:
<! DOCTYPE html>
<HTML>
<HEAD>
<TITLE> Form </TITLE>
</HEAD>
<BODY>
<H1 Align="Center"> <U> Application Form </U></H1>
<FONT SIZE = "5">
<FORM>
User ID :
<INPUT Type="TEXT" Name="EName3" Size="30" Value="Enter User ID"><br><br>
Password :
<INPUT Type = "Password" Name = "Salary" Size = "10"><br><br>
Gender :
<INPUT Type = "Radio" Name = "Gender" Value = "Male" Checked> Male
<INPUT Type = "Radio" Name = "Gender" Value = "Female" > Female <br><br>
Hobbies :<br>
<INPUT Type="Checkbox"Name="Hobbies" Value="Reading"Checked>Reading<br>
<INPUT Type="Checkbox"Name="Hobbies" Value="Reading">Travelling<br>
<INPUT Type="Checkbox"Name="Hobbies" Value="Reading">Playing Games<br>
<INPUT Type="Checkbox"Name="Hobbies" Value="Reading">Singing&Dancing<br>
Select Stream :
<SELECT NAME="List Name">
<OPTION>Science
<OPTION>Commerce
<OPTION>Humanities
</SELECT><br><br><br><br>
<INPUT Type="Submit" Name="Submit" Value="Submit">
</FORM>
</FONT>
</BODY>
</HTML>

In Notepad++

In browser

Try the above codes in Try it Editor
Try it yourself editor
 
Code
Output












    Introduction to HTML


    We surf many websites everyday to find out the information required that time. We find our solutions too by using these websites. But have you ever thought how these amazing websites are made and how does a link work ?
    Yes, this is the subject we will discuss here and the name of the topic is HTML. HTML stands for Hypertext Markup Language.
    A markup language is used to mark the content that helps in designing the web pages. These related web pages make a website.
     
    Hypertext is the way of creating documents that can be displayed on the web and helps to establish link between themselves and cross link to other pages on the web.
    Markup  means identifying or marking the text by applying different formatting features in web documents and producing different types of effect when the document is displayed on web page.
    Language This is the common syntax and rules for writing or marking the text.

    Features of HTML
    i. HTML is not a programming language or any word processing program, rather it is a markup language.
    ii. It is a platform independent language, it can run on any type of operating system like Macintosh, IBM computer etc.
    iii. It is not a case sensitive, we can write tag in any upper or lower case.
    iv. it allows to format text, graphics, audios, videos and save in an ASCII code.

    Requirement to work with HTML
    We need only two things to work in HTML :
    i. Text Editor and             ii. Web browser.

    i. Text Editor : It provides the space where we write text in proper HTML syntex to create a web page.  Some examples are Notepad, Wordpad, Word perfect, KWrite, Front page etc
    After completing the writing text for a web page we save this file with extension .htm or .html.

    ii. Web browser : It is an application software used to display the coded content in text editor in a web page on World wide web or on a local area network. A web page may contain hypertext and the web browser allows to open it in other web page. Examples Google chrome, Internet explorer etc.

    Now we will know some basic terminologies used in HTML.
    1. Tags : These are the keywords of HTML used to define how text, images, audios and videos will appear in a web page. This is the fundamental unit of coded document in HTML and surrounded by angular brackets (<  >). Like <title>, <body> etc. If the tags are not surrounded by angular brackets, HTML takes it as normal text. 
    Tags are of two types. 
    Container Tag and 
    Empty Tag
    A container tag used in pair a opening tag and a closing tag. It defines where or how the structure of the text will appear written under  opening tag and closing tag.
    For example : <title> my first webpage </title>
    Here <title> is an opening tag, </title> is a closing tag  and these two tags defines the text present between both 'my first webpage' will be appeared as title of webpage (Title appears in the title bar of the web  browser). A closing tag is same as opening tag but starts with a back slash.

    An Empty Tag is not used in pairs. It is enough to use it single only. Means it defines the property of the text or document. For example <br> .
    <br> tag is used to give a line break at a particular place in a web page. When a line break appear at a particular place, the afterward texts will appear in next line so no need to give a closing tag.

    2. Element : Elements are the different sections of HTML document, like head, body etc. It is the fundamental component of the structure in an HTML document that includes many different components like title, body, paragraph or list.
    For Ex. <title> my first webpage </title>
    The above whole line is called an element. An element includes
    i. An opening tag
    ii. An closing tag
    iii. The text between the opening and the closing tag.

    3. Attribute : An attribute is the property of a tag, which defines some additional information about that tag. It always specified inside the opening tag. All attributes consist of two parts - a name and a value.
    Here name is the particular property of a tag and
    value is the category of that property.
    For Ex <body bgcolor="red">
    Here body is the tag, bgcolor  (background color) is the attribute and property of the body tag and "red" is the category of background color.
    Means the background color of the body text in a web page should be in red color.
    Now we start coding in HTML so that we can easily understand the structure.

    Fundamental Structure of HTML Document.

    An HTML document consists of text that comprises the content of the document and the tags that defines the structure and the appearance of the document. The basic structure of a HTML document can be classified into different sections called elements.
    HTML Coding Structure


    See the above coding again
    <html>
    <head>
    <title>
    My first web page 
    </title>
    </head>
    <body>
    Welcome to my first web page.
    </body>
    Footer
    </html>
    Here tags <html> and </html> are opening and closing html tags and it includes all the tags and text written  in this page. It shows this is an html document.
    Now <head> and </head> tags are opening and closing head tags. It includes the tags <title> and </title>. The text written with head tag will be displayed above the page as a heading and the text written in between the tags <title> and </title> will be displayed in title bar of the browser.
    Tags <title> and </title> includes the text which will be displayed in title bar.
    Now head section is finished and body section will start from here.
    The text written between <body> and </body> tags are displayed in web page as a content.
    After body tag section you can give the footer information like date of creating this page, time, name of the author(your) etc. But it is an  optional, you can ignore this if you want. 
    Now at last the </html> closing HTML tag is given which means now the page is finished.
    Coding in text editor Notepad++


    Saving an HTML Document.
    After coding as above in any text editor like 'notepad' in Windows or 'gedit' in BOSS Linux, now the time is to save the file.

    Following are the steps to save the file in HTML.

    i. Click file tab -- save as option
    ii. Save as dialog box opens up, in File Name box type any name
    iii. The most important step is after typing the name give a dot (.) and type 'html' or 'htm' as a extension of file.
    iv. Now click 'save' button. The file will look now in form of browser.
    saving of notepad file as my first webpage.html

    Viewing the web page in web browser.
    i. Navigate to the location where you have saved the html file.
    ii. Double click that file (look like a browser). Now the html file opens in default web browser of your computer.
    Here you can see the file, but if you need any change in your html file, then close the file and point that browser with mouse and right click.
    Click 'open with' option select the editor name (like notepad) in which you have typed all coding.
    Now it appears again in text editor form. Do the desired changes and this time click only file tab -- save option. (File name is already given). 

    Running in browser
    Try the above code in Try it Editor
    Try it yourself editor
     
    Code
    Output

    TOP 
















    Python: Functions