HTML Forms and its elements

HTML Form 

A HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using its elements. A form can contain input elements like text fields, checkbox, radio-button, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.

HTML Form - Input Element 

The most important form element is the input element. The input element is used to select user information. An input element can vary in many ways, depending on the type attribute. 

The most used input types are described below.

Text Fields :-

<input type="text" />  : defines a one-line input field that a user can enter text.

Syntax:-

<form>

First name: <input type="text" name="firstname" /><br />

Last name: <input type="text" name="lastname" />

</form>

Password Field :-

<input type="password" />  : defines a password field

Syntax:-

<form>

 Password: <input type="password" name="pwd" />

</form>

Radio Button :-

<input type="radio" />  : defines a radio button. Radio buttons let a user select only one of a limited number of choices: 

Syntax:-

<form>

<input type="radio" name="sex" value="male" />Male<br />

<input type="radio" name="sex" value="female" />Female

</form>

Checkbox :-

<input type="checkbox" />  : defines a checkbox. Checkboxes let a user select One or More options of a limited number of choices. 

Syntax:-

<form>

<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br/>

<input type="checkbox" name="vehicle" value="Car" /> I have a car 

</form>

Submit Button :-

<input type="submit" />  :  defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input.

Syntax:-

<form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" />

<input type="submit" value="Submit" />

</form>

Textarea :-

Textarea:  In a text-area the user can write an unlimited number of characters.

Syntax:-

<textarea> text</textarea>

Attribute of <textarea> tag:

Rows to set the how many no. of rows display 

Cols to set the how many no. of column display 

Example:

<textarea rows=”6” cols=”20”></textarea>

-------------------------------------------------------

Post a Comment

1 Comments