• Tidak ada hasil yang ditemukan

Introduction to HTML Forms

N/A
N/A
Protected

Academic year: 2025

Membagikan "Introduction to HTML Forms"

Copied!
4
0
0

Teks penuh

(1)

Introduction to HTML Forms

Collected by Hossam M.J. Mustafa

- HTML Forms and Input

HTML Forms are used to select different kinds of user input.

Forms

A form is an area that can contain form elements.

Form elements are elements that allow the user to enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.) in a form.

A form is defined with the <form> tag.

<form action=”http://www.kaue.edu.sa/anotherpage.asp" method="GET"

name="form1" target="_blank">

<input>

<input>

</form>

Input

The most used form tag is the <input> tag. The type of input is specified with the type attribute. The most commonly used input types are explained below.

Text Fields

Text fields are used when you want the user to type letters, numbers, etc. in a form.

<form>

First name:

<input type="text" name="firstname" value="enter a value"

disabled="disabled" readonly="readonly" maxlength="50" size="9" /> <br/>

Second name:

<input type="text" name="secondname" value="enter a value"

disabled="disabled" readonly="readonly" maxlength="50" size="9" /> <br/>

Password:

<input type="password" name="password" value="enter a value"

disabled="disabled" readonly="readonly" maxlength="50" size="9" /> <br/>

</form>

How it looks in a browser:

First name:

Last name:

Password:

(2)

Note that the form itself is not visible. Also note that in most browsers, the width of the text field is 20 characters by default.

Radio Buttons

Radio Buttons are used when you want the user to select one of a limited number of choices.

<form>

Gender : <br />

<input type="radio" name="r1" disabled="disabled" readonly="readonly"

value="1" /> Male <br />

<input type="radio" name="r1" disabled="disabled" readonly="readonly"

value="2" checked="checked" /> Female<br />

</form>

How it looks in a browser:

Male Female

Note that only one option can be chosen.

Checkboxes

Checkboxes are used when you want the user to select one or more options of a limited number of choices.

<form>

Permission :

<input type="checkbox" name=" allow1" value="yes" disabled="disabled"

readonly="readonly" checked="checked" /> Allow you to Enter<br />

<input type="checkbox" name="allow2" value="yes" disabled="disabled"

readonly="readonly" checked="checked"/> Allow you to Exit<br />

</form>

How it looks in a browser:

Permission:

Allow you to Enter Allow you to Exit

The Form's Action Attribute and the Submit Button

When the user clicks on the "Submit" button, the content of the form is sent to another file. The form's action attribute defines the name of the file to send the content to. The file defined in the action attribute usually does something with the received input.

<form name="input" action="html_form_action.asp"

method="get">

<input type="button" value="Check" /> <br />

<input type="submit" value="Send Data" /> <br />

<input type="reset" value="Clear Form" /> <br />

</form>

(3)

If you type some characters in the text field above, and click the "Submit" button, you will send your input to a page called "html_form_action.asp". That page will show you the received input.

Text Area

Text Area is used when you want the user to enter a multiline text values.

<form>

Address : <textarea name="Address" cols="20" rows="5" > Put your Address Here</textarea> <br/>

</form>

How it looks in a browser:

Address :

Put your Address Here

Drop Down List

Text Area is used when you want the user to select from a drop down list.

<form>

Age:

<select name="age">

<option value="underage" >less than 20</option>

<option value="20-25" selected="selected" >Around 20-25</option>

<option value="26-35"> Around 26-35</option>

</select> <br />

</form>

Types of Drop down List:

Multiple: Can select multiple values by pressing Ctrl key.

Single: only can select one value.

<form>

Nationality:

<select multiple="multiple" name="nationality">

<option value="KSA" selected="selected" >Saudi Arabia</option>

<option value="JOR">Jordan</option>

</select> <br />

</form>

(4)

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:

<form name="input" action="html_form_action.asp" method="get">

Username: <input type="text" name="user" />

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

</form>

Username

If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input

Reset Button

<input type="reset" /> defines a reset button.

A reset button is used to clear form data:

<form name="input" action="html_form_action.asp" method="get">

Username: <input type="text" name="user" />

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

<input type="reset" value="Reset" />

</form>

Username

If you type some characters in the text field above, and click the "Reset" button, the browser will clear your data in the user text field.

Button

<input type="button" /> defines a simple button.

A simple button is used to do some functionality and defined in the javascript or other client side scripting language:

<form name="input" action="html_form_action.asp" method="get">

Username: <input type="text" name="user" />

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

</form>

Username

If you type some characters in the text field above, and click the "Button" button, the browser will not do anything.

Button

Submit Reset Submit

Referensi

Dokumen terkait

To see your screensavers in action, click on the `Start´ tab in the bottom left hand corner of your computer screen, then click on `Control Panel.´ Once there, click on `Appearance

The inserted row(s) or column(s) will appear below or to the right of the selected entry. Then click the button. Change the entries for the desired number of rows and columns and

Click Save , which puts the file into the directory introtutorial and leads to the Graphic Editor window displayed in Figure 14..

Set the paper type to papertype, usually defined in one of the configuration files, along with the appropriate PostScript code to select it (see Section 4.2 [Config file paper

Hadadi 2018, in his review on the storyline of Robin Hood 2018movie, noted, The latest live-action version of Robin Hood desperately wants viewers to believe this is something

Program design A first iteration through the design process gives a structure something like the following: open the data file for input prompt for and get number identify attribute

A window will appear with the details of the appointment you booked, asking you to enter the confirmation number that you received on your phone number registered in your file

To create the value label Jefferson Valley Bank for J, click in the Value box and type J this box is case sensitive, that is be sure to type J and not j, then click in the Value Label