reading-notes


Project maintained by Razan-am Hosted on GitHub Pages — Theme by mattgraham

HTML & CSS

Chapter 7: “Forms”

Form Controls

  1. Making Choices:
    • Radio buttons:for use when a user must select one of a number of options.
    • Checkboxes:when a user can select and unselect one or more options.
    • Drop-down boxes:when a user must pick one of a number of options from a list.
  2. Submitting Forms:
    • Submit buttons:to submit data from your form to another web page. - Image buttons:similar to submit buttons but they allow you to use an image.
  3. Uploading Files:
    • File upload:allows users to upload files (e.g. images) to a website.

How Forms Work

Writing forms in HTML

The action :Its value is the URL for the page on the server that will receive the information in the form when it is submitted.

Method used to sent the form using get or post methods.

The id is used to identify the form distinctly from other elements on the page.

Example:

<form action="http://www.example.com/subscribe.php" method="get">

<p>This is where the form controls will appear.</p>

</form>

Text Input

Example:

<form action="http://www.example.com/login.php">

<p>Username:

<input type="text" name="username" maxlength="30" />

</p>

</form>

name:It’s used to tell the server which form control each piece of data was entered into. It what will be rendered to the user.

maxlength attribute is used to limit the number of characters a user may enter into the text field.

Password Input

Example:

<form action="http://www.example.com/login.php">

<p>Username:

<input type="text" name="username" maxlength="30" />

</p>

<p>Password: <input type="password" name="password" maxlength="30" />

</p>

</form>

Text Area

Example:

<form action="http://www.example.com/comments.php">

<p>What did you think of this gig?</p>

<textarea name="comments" cols="20" rows="4">Enter your comments...</textarea>

</form>

Any text that appears between the opening <textarea> and closing </textarea> tags will appear in the text box when the page loads.

Radio Button

Example:

<form action="http://www.example.com/profile.php">

<p>Please select your favorite genre:

`
`

<input type="radio" name="genre" value="rock" checked="checked" />

` Rock`

<input type="radio" name="genre" value="pop" />

Pop

<input type="radio" name="genre" value="jazz" />

Jazz

</p>

</form>

The value attribute indicates the value that is sent to the server for the selected option.

The checked attribute can be used to indicate which value (if any) should be selected when the page loads.Only one radio button in a group should use this attribute.

Checkbox

Example:

<form action="http://www.example.com/profile.php">

<p>Please select your favorite music service(s):<br />

<input type="checkbox" name="service" value="itunes" checked="checked" />iTunes

<input type="checkbox" name="service" value="lastfm" /> Last.fm

<input type="checkbox" name="service" value="spotify" /> Spotify

</p>

</form>

Example:

<form action="http://www.example.com/profile.php">

<p>What device do you listen to music on?</p>

<select name="devices">

<option value="ipod">iPod</option>

<option value="radio">Radio</option>

<option value="computer">Computer</option>

</select>

</form>

In drop down list box if the user does not select an option, then the first item will be sent to the server as the value for this control.

Multiple Select Box

Example:

<form action="http://www.example.com/profile.php">

<p>Do you play any of the following instruments?(You can select more than one option by holding down while selecting different options.)</p>

<select name="instruments" size="3" multiple="multiple">

<option value="guitar" selected="selected">Guitar</option>

<option value="drums">Drums</option>

<option value="keyboard" selected="selected">Keyboard</option>

<option value="bass">Bass</option>

</select>

</form>

File Input Box

Example:

<form action="http://www.example.com/upload.php" method="post">

<p>Upload your song in MP3 format:</p>

<input type="file" name="user-song" /><br />

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

</form>

Submit Button

Example:

<form action="http://www.example.com/subscribe.php">

<p>Subscribe to our email list:</p>

<input type="text" name="email" />

<input type="submit" name="subscribe" value="Subscribe" />

</form>

The value attribute is used to control the text that appears on a button.The text will be rendered to the user.

Image Button

Example:

<form action="http://www.example.org/subscribe.php">

<p>Subscribe to our email list:</p>

<input type="text" name="email" />

<input type="image" src="images/subscribe.jpg" width="100" height="20" />

</form>

Button & hidden Controls

Example:

<form action="http://www.example.com/add.php">

<button><img src="images/add.gif" alt="add" width="10" height="10" /> Add</button>

<input type="hidden" name="bookmark" value="lyrics" />

</form>

<An overall about forms>

Labelling Form Controls

Example:

<label>Age: <input type="text" name="age" /></label>

<br/ >

Gender:

<input id="female" type="radio" name="gender" value="f">

<label for="female">Female</label>

<input id="male" type="radio" name="gender" value="m">

<label for="male">Male</label>

<label> element is used with a checkbox or radio button.

Grouping Form Elements

Example:

<fieldset>

<legend>Contact details</legend>

<label>Email:<br />

<input type="text" name="email" /></label><br />

<label>Mobile:<br />

<input type="text" name="mobile" /></label><br />

<label>Telephone:<br />

<input type="text" name="telephone" /></label>

</fieldset>

HTML5: Form Validation

Example:

<form action="http://www.example.com/login/" method="post">

<label for="username">Username:</label>

<input type="text" name="username" required="required" /></title><br />

<label for="password">Password:</label>

<input type="password" name="password" required="required" />

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

</form>

HTML5: Date Input

Example:

<form action="http://www.example.com/bookings/" method="post">

<label for="username">Departure date:</label>

<input type="date" name="depart" />

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

</form>

HTML5: Email & URL Input

  1. Email:
    • By using the <input> tag followed with the type attribute with a value of email to collect an email address data from the user .

Example:

<form action="http://www.example.org/subscribe.php">

<p>Please enter your email address:</p>

<input type="email" name="email" />

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

</form>

  1. URL:
    • By using the <input> tag followed with the type attribute with a value of url to collect from a user a web page address .

Example:

<form action="http://www.example.org/profile.php">

<p>Please enter your website address:</p>

<input type="url" name="website" />

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

</form>

HTML5: Search Input

Example:

<form action="http://www.example.org/search.php">

<p>Search:</p>

<input type="search" name="search" placeholder="Enter keyword" />

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

</form>


Chapter 14: “Lists, Tables & Forms”

Bullet Point Styles

Example:

ol { list-style-type: lower-roman;}

Images for Bullets

Example:

ul { list-style-image: url("images/star.png");}

Positioning the Marker

Example:

ul.illuminations {

list-style-position: outside;}

ul.season {

list-style-position: inside;}

List Shorthand

Example:

ul {

list-style: inside circle;

width: 300px;}

Table Properties

Example:

table {

width: 600px;}

th, td {

padding: 7px 10px 10px 10px;}

th {

text-transform: uppercase;

letter-spacing: 0.1em;

font-size: 90%;

border-bottom: 2px solid #111111;

border-top: 1px solid #999;

text-align: left;}

tr.even {

background-color: #efefef;}

tr:hover {

background-color: #c3e6e5;}

Border on Empty Cells

Example:

td {

border: 1px solid #0088dd;

padding: 15px;}

table.one {

empty-cells: show;}

table.two {

empty-cells: hide;}

Gaps Between Cells

Example:

td {

background-color: #0088dd;

padding: 15px;

border: 2px solid #000000;}

table.one {

border-spacing: 5px 15px;}

table.two {

border-collapse: collapse;}

<Styling Forms>

Styling Text Inputs

Example:

input {

font-size: 120%;

color: #5a5854;

background-color: #f2f2f2;

border: 1px solid #bdbdbd;

border-radius: 5px;

padding: 5px 5px 5px 30px;

background-repeat: no-repeat;

background-position: 8px 9px;

display: block;

margin-bottom: 10px;}

input:focus {

background-color: #ffffff;

border: 1px solid #b1e1e4;}

input#email {

background-image: url("images/email.png");}

input#twitter {

background-image: url("images/twitter.png");}

input#web {

background-image: url("images/web.png");}

Styling Submit Buttons

Example:

input#submit {

color: #444444;

text-shadow: 0px 1px 1px #ffffff;

border-bottom: 2px solid #b2b2b2;

background-color: #b9e4e3;

background: -webkit-gradient(linear, left top,

left bottom, from(#beeae9), to(#a8cfce));

background:

-moz-linear-gradient(top, #beeae9, #a8cfce);

background:

-o-linear-gradient(top, #beeae9, #a8cfce);

background:

-ms-linear-gradient(top, #beeae9, #a8cfce);}

input#submit:hover {

color: #333333;

border: 1px solid #a4a4a4;

border-top: 2px solid #b2b2b2;

background-color: #a0dbc4;

background: -webkit-gradient(linear, left top,

left bottom, from(#a8cfce), to(#beeae9));

background:

-moz-linear-gradient(top, #a8cfce, #beeae9);

background:

-o-linear-gradient(top, #a8cfce, #beeae9);

background:

-ms-linear-gradient(top, #a8cfce, #beeae9);}

Styling Fieldsets & Legends

Example:

fieldset {

width: 350px;

border: 1px solid #dcdcdc;

border-radius: 10px;

padding: 20px;

text-align: right;}

legend {

background-color: #efefef;

border: 1px solid #dcdcdc;

border-radius: 10px;

padding: 10px 20px;

text-align: left;

text-transform: uppercase;}

Aligning Form Controls

Example:

.title {

float: left;

width: 100px;

text-align: right;

padding-right: 10px;}

.radio-buttons label {

float: none;}

.submit {

text-align: right;}

Cursor Styles

-The values for this property:

Example:

a { cursor: move;}


<An overall about lists,tables and forms> -There are several elements are specifically used to control the appearance of lists, tables, and forms.


JAVASCRIPT

Chapter 6: “Events”

Events are used to makes the page feel more interactive.

References:

@Jon Duckett/HTML & CSS @Jon Duckett/JAVASCRIPT