HTML Forms and Frames (2)
HTML Forms and Frames (2)
Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of
a limited number of choices:
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
Checkboxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE
options of a limited number of choices.
<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:
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
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.
More Input Examples
Radio buttons
How to create radio buttons.
<html>
<body>
<form action="">
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
<p><b>
Note:</b> When a user clicks on a radio-button, it becomes checked, and all other radio-buttons
with equal name become unchecked.</p>
</body>
</html>
Checkboxes
How to create checkboxes. A user can select or unselect a checkbox.
<html>
<body>
<form action="">
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
</body>
</html>
Textarea
How to create a multi-line text input control. In a text-area the user can write an unlimited
number of characters.
<html>
<body>
<p>
This example cannot be edited
because our editor uses a textarea
for input,
and your browser does not allow
a textarea inside a textarea.
</p>
<textarea rows="10" cols="30">
The cat was playing in the garden.
</textarea>
</body>
</html>
Create a button
How to create a button.
<html>
<body>
<form action="">
<input type="button" value="Hello world!">
</form>
</body>
</html>
Form Examples
</body>
</html>
HTML Frames
With frames, several Web pages can be displayed in the same browser window.
ATTENTION. Do not expect frames to be supported in future versions of HTML.
Horizontal frameset
How to make a horizontal frameset with three different documents.
<html>
<frameset rows="25%,50%,25%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
</frameset>
</html>
HTML Frames
With frames, you can display more than one HTML document in the same browser window.
Each HTML document is called a frame, and each frame is independent of the others.
The disadvantages of using frames are:
Frames are not expected to be supported in future versions of HTML
Frames are difficult to use. (Printing the entire page is difficult).
The web developer must keep track of more HTML documents
The first column is set to 25% of the width of the browser window. The second column is set to
75% of the width of the browser window. The document "frame_a.htm" is put into the first
column, and the document "frame_b.htm" is put into the second column:
<frameset cols="25%,75%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
</frameset>
Note: The frameset column size can also be set in pixels (cols="200,500"), and one of the
columns can be set to use the remaining space, with an asterisk (cols="25%,*").
Tip: If a frame has visible borders, the user can resize it by dragging the border. To prevent a
user from doing this, you can add noresize="noresize" to the <frame> tag.
Note: Add the <noframes> tag for browsers that do not support frames.
Important: You cannot use the <body></body> tags together with the <frameset></frameset>
tags! However, if you add a <noframes> tag containing some text for browsers that do not
support frames, you will have to enclose the text in <body></body> tags! See how it is done in
the first example below.
More Examples
How to use the <noframes> tag
How to use the <noframes> tag (for browsers that do not support frames).
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
<noframes>
<body>Your browser does not handle frames!</body>
</noframes>
</frameset>
</html>
Nested framesets
How to create a frameset with three documents, and how to mix them in rows and columns.
<html>
<frameset rows="50%,50%">
<frame src="frame_a.htm" />
<frameset cols="25%,75%">
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
</frameset>
</frameset>
</html>
Navigation frame
How to make a navigation frame. The navigation frame contains a list of links with the second
frame as the target. The file called "tryhtml_contents.htm" contains three links. The source code
of the links:
<a href ="frame_a.htm" target ="showframe">Frame a</a><br>
<a href ="frame_b.htm" target ="showframe">Frame b</a><br>
<a href ="frame_c.htm" target ="showframe">Frame c</a>
The second frame will show the linked document.
<html>
<frameset cols="120,*">
<frame src="tryhtml_contents.htm" />
<frame src="frame_a.htm" name="showframe" />
</frameset>
</html>
<html>
<frameset cols="180,*">
<frame src="content.htm" />
<frame src="link.htm" name="showframe" />
</frameset>
</html>