An Introduction To HTML
An Introduction To HTML
An Introduction To HTML
<HTML>
<HEAD>
<TITLE>This is the title of the
document.</TITLE>
</HEAD>
<BODY>This is the body, or main text, of the
document. It can go on for quite a while...
</BODY> </HTML>
OUTPUT
Paragraphs and Spaces
</html>
OUTPUT
Type Styles
HTML allows the use of a number of different type
styles. The most useful are <EM>, for adding
emphasis like this, and <STRONG> for stronger
emphasis. Browsers may display the text in italics,
in bold characters, underlined, in all capital letters, or
with asterisks around it.
In general, it is best to use <EM> and <STRONG>,
since they give good results on all browsers. If you
need to, however, you can use <I>, which produces
italics, or <B> which produces bold text.
There is also typewriter style, like this, produced
with the <TT> tag.
Lists
Lists are a very useful construct in HTML. There
are three types of lists: ordered, unordered, and
descriptive.
Ordered lists produce a list of numbered items.
To make an ordered list, use the <OL> (ordered
list) and <LI> (list item) tags, like this:
<OL><LI>Get two slices of bread, peanut butter, and
jelly.<LI>Spread jelly on one side of one slice of
bread.<LI>Spread peanut butter on the other side of
the other slice.<LI>Put the sandwich together and
eat!</OL>
Cont.
The result is this:
1. Get two slices of bread, peanut butter, and jelly.
2. Spread jelly on one side of one slice of bread.
3. Spread peanut butter on the other side of the other slice.
4. Put the sandwich together and eat!
As you can see, the items are automatically numbered in order.
Unordered lists are similar: instead of <OL>, use <UL>. For example:
Bread (two slices)
Jelly
Peanut Butter
Descriptive lists are a little different: they are used when giving lists of items and
their descriptions, like in a dictionary. The tag for descriptive lists is, predictably,
<DL>, and each item has a <DT> (term to be defined) and <DD> (definition) tag.
The example should make the usage clear:
<DL><DT>This is the first term to be defined<DD>This is the definition of that
term.<DT>piz-za \'pe^-t-se\<DD>an open pie made typically of thinly rolled bread dough
spread with a spiced mixture (as of tomatoes, cheese, and ground meat) and baked</DL>
Example1
html>
<body>
<h4>Numbered list:</h4>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
Cont
<h4>Letters list:</h4>
<ol type="A">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
Cont
<h4>Lowercase letters list:</h4>
<ol type="a">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
Cont
<h4>Roman numbers list:</h4>
<ol type="I">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
Cont
<h4>Lowercase Roman numbers list:</h4>
<ol type="i">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
</body>
</html>
OUTPUT
Example 2
<html>
<body>
</body>
</html>
OUTPUT
Tables
Tables are defined with the <table> tag. A table is
divided into rows (with the <tr> tag), and each
row is divided into data cells (with the <td>
tag). The letters td stands for "table data,"
which is the content of a data cell. A data cell
can contain text, images, lists, paragraphs,
forms, horizontal rules, tables, etc.
<table border="1"><tr><td>row 1, cell
</body>
</html>
Output
Table Tags
Tag
Description
<table>
Defines a table
<th>
Defines a table header
<tr>
Defines a table row
<td>
Defines a table cell
<caption>
Cont
Defines a table caption
<colgroup>
Defines groups of table columns
<col>
Defines the attribute values for one or more columns in
a table
<thead>
Defines a table head
<tbody>
Defines a table body
<tfoot>
Defines a table footer
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 Frameset Tag
The <frameset> tag defines how to divide the
window into frames
Each frameset defines a set of rows or columns
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
<frame src="frame_c.htm">
</frameset>
</html>
OUTPUT
Examples according to Rows
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
<frame src="frame_c.htm">
</frameset>
</html>
OUTPUT
Pictures
Adding pictures to an HTML document is easily
done. First of all: pictures are almost always in
GIF or JPG format, which can easily be read by
any computer and browser. It should not be too
difficult to find a program to convert your
existing pictures to GIFs or JPGs. Also, GIFs
should have a ".gif" at the end of the filename;
JPGs should have a ".jpg" at the end of the
filename.
Cont.
To show an image, use the <IMG> tag. The
usage is a little different than the other tags
we've seen before. By IPECelf, the <IMG> tag
does nothing; you must use the SRC=""
attribute in the tag to specify the name of the
image. Inside the quotes of the SRC="", insert
the URL of the image. An example:
Here is a picture of Elvis: <IMG SRC="elvis.gif">
Here is a picture of Elvis:
Links
A full explanation of how to create links between
documents is beyond the scope of this
document. However, we can give a quick
introduction.
Links, sometimes referred to as "anchors", are
specified with the <A> tag. Like the <IMG> tag,
<A> does nothing by IPECelf. The HREF=""
attribute specifies the URL that the link points
to. As always, an example:
If you click <A HREF="link.html">here</A>, you
will seethe file "link.html".
Other Random Tags
There are a number of other tags, more and less
useful. A quick survey:
<PRE>
Preformatted text: rendered in a monospace
font. Unlike most HTML, white space is
significant. Tags are still honored, though. This
style is useful for tables of information, since
tabs work.
<LISTING>
Similar to <PRE>, but in a smaller size. Meant
for program listings. Supposedly, embedded tags
are ignored.
<BLOCKQUOTE>
How to make Forms
<form method="post" action="mailto:
your email address here">
Next you want to actually start your
form:
First Name: <input name="first"
type="text" size=12>
Last Name: <input name="last"
type="text" size=12>
Email Address: <input name="address"
type="text" size=30>
Cont.
Comments:
<textarea name="whatever" rows=5 cols=30>
</textarea>
<select name="whatever" size=4>
<option>choose me <option>choose me
<option>choose me <option>choose me
<option>choose me
</select>
Now you want your buttons at the bottom
of the form:
<input type="Submit" value="Send it in"> <input
type="reset" value="reset">
Cont.
</html
Output
Another Example
<html>
<body>
<script language="javascript">
var name = "Hege"
document.write(name)
document.write("<h1>"+name+"</h1>")
</script>
Cont
<p>This example declares a variable, assigns a
value to it, and then displays the variable.</p>
</body>
</html>
Output
Cont
HegeHege
This example declares a variable, assigns
a value to it, and then displays the
variable.
Then the variable is displayed one more
time, only this time as a heading.
Alert() method
</body>
</html>
Break statement
<html> <body>
<script language="javascript">
for(var i=0; i<5; i++)
{
if(i == 3)
break;
document.write("i is - "+i);
}
document.write(" --------- After Looping------ ");
</script>
</body></html>
JavaScript Functions
<script language="javascript">
function myfunction()
{
alert("HELLO")
}
</script>
</head>
Cont
<body>
<form>
<input type="button"
onclick="myfunction()"
value="Call function">
</form>
<p>By pressing the button, a function will be
called. The function will alert a message.</p>
</body>
</html>
Output
Output
JavaScript Arrays - creating
and storing values
An array can be regarded as a set of
variables. This does not mean that the
variables in an array are related to each
other; they are still separate entities in
themselves. Arrays helps us group
variables, which we plan to use for a
particular purpose because accessing their
values becomes a lot easier this way.
Cont.
Let's see how we make an array.
var city = new Array(); Each array is
initialized using the new keyword with the
Array() construct (Isn't this similar to
using Date()?). So here we initialize and
array called city. Now we fill this array
with our values (city names).
Cont
city[0] = "New York"; city[1] = "London";
city[2] = "New Delhi"; city[3] = "Sydney";
city[4] = "Tokyo"; city[5] = "Moscow"; city[6]
= "Lima";
Example
<html>
<head>
<title>Javascipt - array plus manipulation</title>
<script language=“javascript ">
function array() { }
student = new array()
student[1] = 23
student[2] = 34
student[3] = 67
student[4] = 76
student[5] = 51
student[6] = 72
Cont
document.writeln("<h2>Student
results</h2>")
document.writeln("<ul>")
numStudents = 0
sum=0
ans=0
Cont
for (i in student){
document.writeln("<li>Student " + i + ": " +
student[i] + "%")
numStudents++
sum=sum+student[i]
}
document.writeln("</ul>")
ans = Math.round(sum/numStudents)
document.writeln("student average is " + ans +
"%")
Cont
</script>
</head>
<body>
<br>
</body>
</html>
Output
The JavaScript prompt -
Getting user input
The prompt() is a method of the window
object, just like alert() or confirm().
The format for prompt() is similar to
alert() or confirm() except for one
addition.
prompt("Message", "default value in the text
field");
Prompt() Example
<html>
<body>
<script language="JavaScript">
function function1() {
window.prompt("Please, enter your full name", "Yes,
here");
}
</script>
<input type="button" value="Open a prompt window" o
nclick="function1();">
</body>
</html>
Output
Date and Time in JavaScript