html review html and javascript. 2 what is html? html stands for hypertext markup language it is the...

145
HTML Review HTML and JavaScript

Upload: kristian-daniel

Post on 29-Dec-2015

226 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

HTML Review

HTMLand

JavaScript

Page 2: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

2

What is HTML?

• HTML stands for HyperText Markup Language

• It is the set of instructions hidden behind every web page (called the source of the page)

• HTML “tags” tell the browser (like Internet Explorer) how to display the page.

• For example, <B>HI THERE</B> would display the words HI THERE in bold.

Page 3: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

3

What is HTML?

• HTML “tags” are contained within < > • The letters inside the < > are the

instructions (like <B> for bold) and may be upper or lower case.

• Tags often come in pairs…one to begin a feature, and another to end it.

• In the previous example, <B> means “begin bold here” and </B> means “end bold here”.

Page 4: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

4

HTML Structure

• Each web page has a HEAD and a BODY.

• All web pages have required tags like these: <HTML> {begin the page} <HEAD> {some set up instructions </HEAD> are here} <BODY> {the main part of the page </BODY> is here} </HTML> {end the page}

Page 5: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

5

HTML Structure

• The HEAD section often contains tags to display a page title.

• The title is displayed at the top of the window (not on the page).

• Here is an example: <HEAD> <TITLE>My Web Page</TITLE> </HEAD>

Page 6: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

6

HTML Structure

• The BODY section contains all the instructions for the actual page display.

• Inside the body section of a web page you will find tags that control text, graphics, lines, links, tables and other special functions.

• Remember that some, but not all, tags come in pairs.

Page 7: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

7

Text-Related Tags

• Text is most often displayed in paragraphs, using block form.

• The paragraph tags <P> and </P> are used before and after a paragraph.

• <BR> (“line break”) is like pressing Return/Enter. The text that follows is displayed on the next line.

• NOTE: Just pressing Return/Enter when you are writing a page in HTML does not guarantee that it will be displayed on the next line.

Page 8: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

8

Text-Related Tags

• Text is sometimes displayed in BOLD or ITALICS.

• The tag pair <B> and </B> make the text between display in bold.

• The tag pair <I> and </I> make the text between display in italics.

• Examples: <B>This is bold text.</B> This is bold

text. <I>Here is italics.</I> Here is italics. <B><I>Both!</I></B> Both!

Page 9: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

9

Text-Related Tags

• NOTE: Though there is a tag for underlining (<U> </U>) it is not a good idea to underline text. It may be confused with a link, since they are usually underlined.

• The <FONT> </FONT> tag pair can be used to change other aspects of text (e.g., color).

Page 10: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

10

Text-Related Tags

• You will often see text displayed in large, bold type, almost like a newspaper headline.

• The “header” tags are used for this purpose.• The largest “header” tag is <H1> </H1>

(larger numbers make smaller headers).

• An example: <H1>MY PAGE</H1> displays

MY PAGE• <H6>MY PAGE</H6> displays MY PAGE

Page 11: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

11

Text-Related Tags

• To center a header, the tag pair <CENTER> </CENTER> is used.

• An example:<CENTER><H1>TRAINS</H1></CENTER>

displays… TRAINS

Page 12: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

12

Lines

• Many web pages use horizontal lines to divide the page.

• The <HR> tag is used to draw a line.• You can control the size (thickness in

pixels) and width (% of the window).• Examples:

<HR> {one pixel thick, 100% of window} <HR SIZE=4 WIDTH=50%>

{4 pixels thick, 50% of window}

Page 13: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

13

IMAGE Tags

• The <IMG> tag is used to display graphics on web pages.

• The main requirement for the IMG tag is the file name (“source”) of the image.

• NOTE: Web page images DO NOT become part of a web page file. They are separate files and must be located in the same folder as the web page file unless otherwise noted.

Page 14: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

14

IMAGE Tags

• An example of an IMG tag that displays a graphic called ME.JPG <IMG SRC=“ME.JPG”>

• In the example above, the name (“source” or SRC) of the picture file is ME.JPG (stored in the same folder as the web page file).

• NOTE: The image file’s name must be exactly as stored (upper/lower case, etc.)

• .JPG and .GIF indicate types of images appropriate for web pages.

Page 15: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

15

Lists

• Many web pages contain lists.• Lists can be “unordered” (using bullets

like this list) or “ordered” (with numbers or letters).

• <UL> </UL> indicates an unordered (bulleted) list.

• <OL> </OL> indicates an ordered list.• <LI> </LI> is used for each list item.

Page 16: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

16

List Examples

These tags…• <UL>• <LI>Dogs</LI>• <LI>Cats</LI>• <LI>Lizards</LI>• </UL>

Produce this list…• Dogs• Cats• Lizards

Page 17: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

17

List Examples

These tags…• <OL>• <LI>Dogs</LI>• <LI>Cats</LI>• <LI>Lizards</LI>• </OL>

Produce this list…1. Dogs2. Cats3. Lizards

Page 18: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

18

List Examples

These tags…• <OL TYPE=“A”>• <LI>Dogs</LI>• <LI>Cats</LI>• <LI>Lizards</LI>• </OL>

Produce this list…A. DogsB. CatsC. Lizards

Page 19: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

19

A Word about Links

• All links use the tag that begins <A HREF=

• The A stands for “anchor” (think of an anchor chain..it’s made of links…right?).

• The HREF part will be the name of a web page or a web address.

Page 20: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

20

A Word about Links

• Here are a couple of examples, you will see the actual message to click on between the “A” tags.

• This link shows the words Go Back and sends the user to a page called HOME.HTM that is stored in the same folder as the current page. <A HREF=“HOME.HTM”>Go Back</A>

Page 21: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

21

A Word about Links

• This link shows the words More Info and sends the user to the CSUH home page.

<A HREF=“http://www.csuhayward.edu/”>More Info</A>

Page 22: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

22

More about Links

• Virtually every web page has links…it’s the basic idea of the web and HTML (HyperText refers to links).

• Link tags look like this:<A HREF=“address”>what to click

on</A>• The address can be a file name (like

home.htm) or a web address (like http://www.csuhayward.edu)

Page 23: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

23

More about Links

• The “what to click on” is quite often text.• Whatever is placed between the <A> tags

is displayed on the screen and usually underlined (though you can change it in your browser settings).

• You can also place an < IMG> tag between the <A> tags, making the image into a link.

Page 24: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

24

More about Links

• The example below shows an image called TOY.JPG as a link to a page called TOYSTORY.HTM :

<A HREF=“TOYSTORY.HTM”><IMG SRC=“TOY.JPG”></A>

• The <IMG> tag may also contain HEIGHT, WIDTH, and BORDER information.

• This way, however, the user will not know that the image is a link. See the next slide for a better idea.

Page 25: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

25

More about Links

• In the example below, both the image TOY.JPG and the words “GO TO TOY STORY” are part of the link to TOYSTORY.HTM.

<A HREF=“TOYSTORY.HTM”>GO TO TOY STORY<IMG SRC=“TOY.JPG”></A>

• The words in the link can come before or after the <IMG> tag. Placement of text is next to images.

Page 26: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

26

More about Links

• Sometimes it is convenient to have a list of links. See the example below:

<UL><LI><A HREF=“http://www.csuhayward.edu/”>CSUH

</A></LI><LI><A HREF=“http://www.csuhayward.edu/math/>”

College of Math </A></LI><LI><A

HREF=“http://www.csuhayward.edu/bhecker”> Barbara’s Classes</A></LI>

</UL>

Page 27: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

27

Colors in HTML

• When you specify colors in HTML, you can either enter a color by name (for simple colors) OR…

• You can put in codes that specify the amount of red, green and blue to include in the color (which gives you millions of combinations).

Page 28: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

28

Colors in HTML

• Here is an example of the use of color in a <FONT> tag. The text will print in red.

<FONT color=“red”>The text.</FONT>• Here is another way to say “red”: <FONT color=“#FF0000”>The

text.</FONT> (weird, huh?)

greenred

blue

Page 29: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

29

Colors in HTML

• What’s all this “#FF” stuff?• If you want more than simple colors, you

must specify the amount of red, green, and blue in the color.

• This is done with six hexadecimal (base 16) numbers (that’s what # means) - two each for red, green and blue.

• Each pair of numbers ranges from 00 to FF (yes, FF is a number) 00 = none, FF = highest

Page 30: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

30

Colors in HTML

• Here are some sample color numbers:RED #FF0000 (high red, no green, no blue)GREEN #00FF00 (no red, high green, no blue)BLUE #0000FF (no red, no green, high blue)BLACK #000000 (no red, no green, no blue)WHITE #FFFFFF (high red, high green, high blue)YELLOW #FFFF00 (high red, high green, no blue)CYAN #00FFFF (no red, high green, high blue)MAGENTA #FF00FF (high red, no green, high blue)

Page 31: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

31

Colors in HTML

• Another place to use color is for a background.

• Background color is specified in the <BODY> tag.

• For example, to set the background of a page to light blue, use

<BODY BGCOLOR=“light blue”>

Page 32: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

32

Colors in HTML

• You can also set the link color and text color for the whole page in the <BODY> tag.

• Here is a tag that sets the background to yellow, the text to red, the links to blue, and the visited links (the ones you have already been to) to purple:

<BODY BGCOLOR=“yellow” TEXT=“red” LINK=“blue” VLINK=“purple”>

Page 33: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

33

More about Text Size

• You know “header” tags make large text (like <H1></H1>)

• You can also specify text size with a <FONT> tag.

• Here is an example of very small text:<FONT SIZE=1>Write this.</FONT>

Page 34: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

34

More about Images

• Web page images are displayed on the left side of a page and in their actual stored size unless otherwise instructed.

• The HEIGHT and WIDTH of an image can be specified in the IMG tag.

• HEIGHT and WIDTH are measured in pixels.

Page 35: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

35

More about Images

• Example:<IMG SRC=“MyPicture.gif” HEIGHT=100

WIDTH=50>

• The example above displays the graphic file MyPicture.gif with a height of 100 pixels and a width of 50 pixels.

• NOTE: If you do not specify HEIGHT and WIDTH, the image will appear the size at which it was stored.

Page 36: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

36

More about Images

• To align an image at the center or the right of the screen, it is easiest to use one of the following tag pairs:<CENTER> </CENTER><RIGHT> </RIGHT>

• The IMG tag is placed between the alignment tags:<CENTER><IMG SRC=“picture.jpg”></CENTER> NOTE: If you place several IMG tags in a row (one for each picture),

they will appear next to each other when the page is displayed.

Page 37: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

37

More about Images

• If you want a border (like a frame) around the image, you can put BORDER=thickness in pixels in the IMG tag. Example:<IMG SRC=“kitty.jpg” BORDER=3>

• Here is an example of an image called BOG.gif which is centered, displayed 200 x 200, with a 4-pixel border.

<CENTER><IMG SRC=“BOG.gif” HEIGHT=200 WIDTH=200

BORDER=4></CENTER>

Page 38: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

38

Image Maps

• You have learned that a graphic can be a link.

• With an image map, a single graphic can be used to link to several different sites.

• Coordinates within an image are used to “map” various areas, each of which may be used as a link to a different web page.

Page 39: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

39

Image Maps

• If you could see an image with its map, it might look like this:

Each area could be a separate link.

This area might link to FEET.HTM

These areas might link to EAR.HTM

Page 40: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

40

Image Maps

• Each area is defined by coordinates in pixels.

• For rectangular areas, it is the upper left and lower right.

This area might be defined as 2,200 (upper left) 205,300 (lower right)

Page 41: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

41

Image Maps

• The HTML code to make an image map begins with the IMG tag.

• Here is a sample: <IMG SRC=“pig.gif” USEMAP=“#MIG”>• USEMAP says that the graphic is an

image map.• MIG is the name of the map definition (#

means “look in this same document”).

Page 42: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

42

Image Maps

• The image map definition begins with a map tag:

<MAP NAME=“MIG”>• The name of this map definition is

MIG.• </MAP> ends the definition.• The lines in between describe the

areas (by coordinates) and the web pages that they link to.

Page 43: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

43

Image Maps

• The lines between <MAP NAME=“MIG”> and </MAP> define the areas, one tag for each area.

• Here is an example from the pig: <AREA SHAPE=RECT HREF=“FEET.HTM”

COORDS=“2,200 205,300”>• The shape of the area is a rectangle, the

link goes to FEET.HTM, the upper left of the rectangle is at 2,200 and the lower right of the rectangle is at 205,300.

Page 44: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

44

Image Maps

• How can I find the coordinates?• You can search shareware sites for

image map programs.• You can use a graphics program, if it

shows the position of the cursor with “pixels”.

• Move the cursor over the picture and write down the appropriate coordinates.

Page 45: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

45

Frames

• A FRAMESET document uses <FRAMESET> and </FRAMESET> instead of <BODY> and </BODY>.

• The type of frames (rows or columns) must be specified, and each frame must be described with a <FRAME> tag like this:

<FRAME SRC =”content1.htm" border="0" NORESIZE >

Page 46: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

46

FRAMESET Sample

• Here is the FRAMESET code for the example --><HTML><HEAD></HEAD><FRAMESET

COLS=“100,*”><FRAME SRC=“left.htm”><FRAME SRC=“right.htm”></FRAMESET></HTML>

Links•One•Two•Three

WELCOME!

Join us..etc.

left.htm

right.htm

Page 47: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

47

FRAMESET Sample

<HTML><HEAD></HEAD><FRAMESET

COLS=“100,*”><FRAME

SRC=“left.htm”><FRAME

SRC=“right.htm”></FRAMESET></HTML>

• Two “column” frames - the first (left) is 100 pixels wide. The right frame takes up whatever space is left over (*) on the screen.

• left.htm is the web page file for the left frame.

• right.htm fills the right frame.

Page 48: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

48

Self Check - Example Questions

• Which of the following is NOT a required tag? <HTML> </BODY> <H1> <HEAD>

Page 49: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

49

Self Check - Example Questions

• Which of the following is NOT a required tag? <HTML> </BODY> <H1> {headings/headlines are common, but

not required}

<HEAD>

Page 50: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

50

Self Check - Example Questions

• Which of the tags below will show the words MY PAGE on the page in very large type? <TITLE>MY PAGE</TITLE> <H1>MY PAGE</H1> <H7>MY PAGE</H7> <FONT SIZE=2>MY PAGE</FONT>

Page 51: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

51

Self Check - Example Questions

• Which of the tags below will show the words MY PAGE on the page in very large type? <TITLE>MY PAGE</TITLE> <H1>MY PAGE</H1> {H1 shows the largest

“headline”}

<H7>MY PAGE</H7> <FONT SIZE=2>MY PAGE</FONT>

Page 52: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

52

Self Check - Example Questions

• Which set of tags below would display this text in italics and bold: CLICK HERE <I><B>CLICK HERE</I></B> <I><B>CLICK HERE</B></I> <B>CLICK HERE</B> <H1>CLICK HERE</H1>

Page 53: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

53

Self Check - Example Questions

• Which set of tags below would display this text in italics and bold: CLICK HERE <I><B>CLICK HERE</I></B> <I><B>CLICK HERE</B></I> * <B>CLICK HERE</B> <H1>CLICK HERE</H1>

*Explanation: Tags must be “nested” - the first to be turned on must be the last to be turned off.

Page 54: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

54

Self Check - Example Questions

• To put a blank line after typing… <BR> <P> and </P> Just press Return/Enter Either <BR> or <P></P> will work.

Page 55: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

55

Self Check - Example Questions

• To put a blank line after typing… <BR> <P> and </P> Just press Return/Enter Either <BR> or <P></P> will work.

Page 56: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

56

Self Check - Example Questions

• Which the the following makes a “numbered” list (1., 2., etc.)?

• <OL></OL>• <LI></LI>• <UL></UL>• <NL></NL>

Page 57: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

57

Self Check - Example Questions

• Which the the following makes a “numbered” list (1., 2., etc.)?

• <OL></OL> {a numbered list is an “ordered” list}

• <LI></LI>• <UL></UL>• <NL></NL>

Page 58: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

58

Self Check - Example Questions

• To draw a line across the web page, use… <HR> <LINE> <LI></LI> Must use a graphic.

Page 59: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

59

Self Check - Example Questions

• To draw a line across the web page, use… <HR> {a line is a “horizontal rule”}

<LINE> <LI></LI> Must use a graphic.

Page 60: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

60

Self Check - Example Questions

• Which of the following displays the words CLICK ME as a link to homepage.htm?

<LI “homepage.htm”>CLICK ME</LI> <LI “CLICK ME”>homepage.htm <A HREF=”homepage.htm”>CLICK

ME</A> <LINKTO “homepage.htm”>CLICK ME

Page 61: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

61

Self Check - Example Questions

• Which of the following displays the words CLICK ME as a link to homepage.htm?

<LI “homepage.htm”>CLICK ME</LI> <LI “CLICK ME”>homepage.htm <A HREF=”homepage.htm”>CLICK

ME</A> <LINKTO “homepage.htm”>CLICK ME

Page 62: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

62

Self Check – Example Questions

• Which command is used to set the background color of a web page to white…

<BODY BGCOLOR=“WHITE”><BODY BGCOLOR=“#000000”><BODY BGCOLOR=“NONE”>

Page 63: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

63

Self Check – Example Questions

• To set the background color of a web page to white…

<BODY BGCOLOR=“WHITE”><BODY BGCOLOR=“#000000”><BODY BGCOLOR=“NONE”>

Page 64: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

64

Self Check – Example Questions

• Which of the following places a graphic called “dog.jpg” on a web page?

<IMG SRC=“dog.jpg”><IMG SRC=“DOG.JPG”><GRP SRC=“dog.jpg”><IMG GRP=“dog.jpg”>

Page 65: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

65

Self Check - Example Questions

• Which of the following places a graphic called “dog.jpg” on a web page?

<IMG SRC=“dog.jpg”><IMG SRC=“DOG.JPG”> {case must match file name}

<GRP SRC=“dog.jpg”><IMG GRP=“dog.jpg”>

Page 66: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

66

Self Check - Example Questions

• Which of the following sets the size of dog.jpg to 100 x 100 pixels?

<IMG SRC=“dog.jpg” SIZE = “100x100”><IMG SRC=“dog.jpg” SIZE1=100

SIZE2=100><IMG SRC=“dog.jpg” HEIGHT=100

WIDTH=100>

Page 67: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

67

Self Check - Example Questions

• Which of the following sets the size of dog.jpg to 100 x 100 pixels?

<IMG SRC=“dog.jpg” SIZE = “100x100”><IMG SRC=“dog.jpg” SIZE1=100

SIZE2=100><IMG SRC=“dog.jpg” HEIGHT=100

WIDTH=100>

Page 68: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

68

Self Check - Example Questions

• Which of the following creates a link to HOME.HTM by clicking GO HOME?

<A HREF=“GO HOME”>HOME.HTM</A> <A HREF=“HOME.HTM”>GO HOME</A> <IMG HREF=“HOME.HTM”>GO

HOME</A> <IMG HREF=“GO

HOME”>HOME.HTM</A>

Page 69: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

69

Self Check - Example Questions

• Which of the following creates a link to HOME.HTM by clicking GO HOME?

<A HREF=“GO HOME”>HOME.HTM</A> <A HREF=“HOME.HTM”>GO HOME</A> <IMG HREF=“HOME.HTM”>GO

HOME</A> <IMG HREF=“GO

HOME”>HOME.HTM</A>

Page 70: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

70

Self Check - Example Questions

• Which of the following allows the user to click on GO HOME or a graphic (home.jpg) to go to HOME.HTM?

<A HREF=“HOME.HTM><IMG SRC=“home.jpg”>GO HOME</A>

<A HREF=“HOME.HTM>GO HOME<IMG SRC=“home.jpg”></A>

<A HREF=“HOME.HTM><IMG SRC=“home.jpg”></A>

Page 71: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

71

Self Check - Example Questions

• Which of the following allows the user to click on GO HOME or a graphic (home.jpg) to go to HOME.HTM?

<A HREF=“HOME.HTM><IMG SRC=“home.jpg”>GO HOME</A>

<A HREF=“HOME.HTM>GO HOME<IMG SRC=“home.jpg”></A>

<A HREF=“HOME.HTM><IMG SRC=“home.jpg”></A>

{Either graphics first or words first}

Page 72: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

72

Self Check - Example Questions

• Which of the lists below will results from these tags?<OL><LI><A HREF=“MINE.HTM”>See Me</A></LI><LI>GO AWAY!</LI></OL>

1. See Me

2. GO AWAY!

1. See Me

2. GO AWAY!

1. See Me

2. GO AWAY!

Page 73: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

73

Self Check - Example Questions

• Which of the lists below will results from these tags?<OL><LI><A HREF=“MINE.HTM”>See Me</A></LI><LI>GO AWAY!</LI></OL>

1. See Me

2. GO AWAY!

1. See Me

2. GO AWAY!

1. See Me

2. GO AWAY!

Page 74: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

74

Self Check - Example Questions

• Which is the correct text placement if this tag is used? <IMG SRC=“SOS.GIF” ALIGN=TOP>SINK!

SINK!SINK!

SINK!

Page 75: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

75

Self Check - Example Questions

• Which is the correct text placement if this tag is used? <IMG SRC=“SOS.GIF” ALIGN=TOP>SINK!

SINK!SINK!

SINK!

Page 76: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

76

Self Check - Example Questions

• To use a graphic (back1.gif) as a page background, use… <BODY BACKGROUND=“back1.gif”> <BODY><IMG

SRC=“back1.gif”></BODY> <BODY BGCOLOR=“back1.gif”> You cannot use a graphic as a

background.

Page 77: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

77

Self Check - Example Questions

• To use a graphic (back1.gif) as a page background, use… <BODY BACKGROUND=“back1.gif”> <BODY><IMG

SRC=“back1.gif”></BODY> <BODY BGCOLOR=“back1.gif”> You cannot use a graphic as a

background.

Page 78: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

78

Self Check - Example Questions

• If a background graphic is smaller than the page display… The image is displayed larger to fill the

window. The image is centered on the page

window. The image is tiled (repeated).

Page 79: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

79

Self Check - Example Questions

• If a background graphic is smaller than the page display… The image is displayed larger to fill the

window. The image is centered on the page

window. The image is tiled (repeated).

Page 80: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

80

Self Check - Example Questions

• To use an image (lineup.gif) as a line, use the following tag(s)… <HR><IMG SRC=“lineup.gif”></HR> <IMG SRC=“lineup.gif”> <HR SRC=lineup.gif”> <HR>lineup.gif</HR>

Page 81: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

81

Self Check - Example Questions

• To use an image (lineup.gif) as a line, use the following tag(s)… <HR><IMG SRC=“lineup.gif”></HR> <IMG SRC=“lineup.gif”> <HR SRC=lineup.gif”> <HR>lineup.gif</HR>

Page 82: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

82

Self Check – Example Questions

• Which of the following graphics formats would need to be converted before using on a web page? GIF JPG TIFF BMP PICT

Page 83: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

83

Self Check - Example Questions

• Which of the following graphics formats would need to be converted before using on a web page? GIF JPG TIFF BMP {You will need a graphics

PICT conversion program}

Page 84: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

84

Self Check - Example Questions

• An image map is… A GIF that shows a map of a country A graphic that links to several different

web pages A graphic that links to a single web page There is no such thing!

Page 85: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

85

Self Check - Example Questions

• An image map is… A GIF that shows a map of a country A graphic that links to several different

web pages A graphic that links to a single web page There is no such thing!

Page 86: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

86

Self Check - Example Questions

• Which of the following tags shows a rectangular area linking to home.htm with coordinates of 100,100 and 300,400?

• <AREA SHAPE=RECT HREF=“home.htm” COORDS=“100,100,200,400”>

• <AREA SHAPE=RECT HREF=“home.htm” COORDS=“100,100 200,400”>

Page 87: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

87

Self Check - Example Questions

• Which of the following tags shows a rectangular area linking to home.htm with coordinates of 100,100 and 200,400?

• <AREA SHAPE=RECT HREF=“home.htm” COORDS=“100,100,200,400”>

• <AREA SHAPE=RECT HREF=“home.htm” COORDS=“100,100 200,400”>

{No comma between sets of coordinates}

Page 88: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

JavaScript

Page 89: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

89

What is JavaScript?

• JavaScript is a programming language. This means that the instructions you write in JavaScript will make something happen.

• You can include it easily within the HTML code of a web page to customize the page.

Page 90: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

90

What is JavaScript?

• JavaScript is related to Java and C++, but it does not need to be “compiled” (translated to binary) before it is used.

• JavaScript is not the same as Java.

Page 91: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

91

What is JavaScript?

• JavaScript code is “interpreted” - the browser executes each line of code as it is encountered.

• JavaScript is free and many existing samples are available.

Page 92: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

92

How do you add JavaScript to a web page?

• When you copy or type the code, notice where it should go.

• JavaScript is most commonly placed in the <HEAD> section of a page, but there are often parts that must go elsewhere.

Page 93: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

93

JavaScript - Sample

• Here is an explanation of a simple use of JavaScript - asking a question and displaying an answer.

• In this case, there will be a JavaScript function (small program) called getName() placed in the HEAD section of the HTML.

• It will ask for a name and print Hi and the name.

Page 94: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

94

JavaScript - Sample

• Here’s what the function looks like:

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 95: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

95

JavaScript - Sample

• The script tags are needed to identify this code as JavaScript.

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 96: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

96

JavaScript - Sample

• The line beginning var sets up a variable called stName with a beginning value of XX.

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 97: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

97

JavaScript - Sample

• function getName() defines the name of the function (notice the two parentheses).

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 98: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

98

JavaScript - Sample

• The braces ({ and }) show where the function begins and ends.

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 99: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

99

JavaScript - Sample

• The line beginning stName= displays the message Please enter your name and waits for an entry, which will be the value of stName.<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 100: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

100

JavaScript - Sample

• The line beginning alert displays Hi, and the value of the variable stName.

<script language="JavaScript">var stName="XX"function getName( ) {stName=prompt("Please enter your name"," ") alert("Hi, " + stName)} </script>

Page 101: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

101

JavaScript - Sample

• Something has to start the getName() function.

• This can be done by the user clicking on a graphic or a “form” button.

Page 102: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

102

JavaScript - Sample

• To start a function, its name will be somewhere in the HTML: getName()

• You will see this code in an IMG tag: onclick=“getName()”

• When the graphic is clicked, the function starts.

Page 103: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

103

JavaScript - Sample

• You will also see this code between <FORM> tags: <input value="HI" onclick="getName()" type="button">

• FORMs are used to make buttons and input boxes appear on a web page.

Page 104: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

104

Self Check – Example Questions

• True or false - JavaScript and Java are exactly the same thing.

Page 105: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

105

Self Check - Example Questions

• True or false - JavaScript and Java are exactly the same thing.

• False - Java must be “complied” (translated to binary) before running, while JavaScript runs automatically every time the web page is opened. Java is also much more powerful than JavaScript.

Page 106: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

106

Self Check - Example Questions

• JavaScript is most often found in the _____ section of the HTML code for a web page.

<HEAD> <BODY> <TABLE> <LIST>

Page 107: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

107

Self Check - Example Questions

• JavaScript is most often found in the _____ section of the HTML code for a web page.

<HEAD> <BODY> {may be here, too}

<TABLE> <LIST>

Page 108: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

108

Self Check - Example Questions

• Which of the following is the correct way to begin JavaScript?

<SCRIPT LANGUAGE=“Javascript”> <SCRIPT LANGUAGE=“JavaScript”> <JAVASCRIPT> <JavaScript>

Page 109: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

109

Self Check - Example Questions

• Which of the following is the correct way to begin JavaScript?

<SCRIPT LANGUAGE=“Javascript”> <SCRIPT LANGUAGE=“JavaScript”> * <JAVASCRIPT> <JavaScript>* {upper and lower case must be exact}

Page 110: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

110

Self Check - Example Questions

• Suppose you created the function shown below. What command would activate the function? function HAPPY()

• happy()• HAPPY• HAPPY()

Page 111: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

111

Self Check - Example Questions

• Suppose you created the function shown below. What command would activate the function? function HAPPY()

• happy()• HAPPY• HAPPY() {case sensitive; must include ( )}

Page 112: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

112

Self Check - Example Questions

• Which of the following commands waits for input?

prompt alert

Page 113: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

113

Self Check - Example Questions

• Which of the following commands waits for input?

prompt {waits for input and Return/Enter}

alert {displays message only}

Page 114: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

114

Object-Oriented Programming

• Programming languages come in many varieties.

• Older languages like BASIC and FORTRAN accepted input from the user and displayed information.

• They could not directly influence “objects” such as graphics or text boxes.

Page 115: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

115

Object-Oriented Programming

• JavaScript (and other contemporary languages) are classified as object-oriented, because they can affect objects on the screen.

• For example, JavaScript can be used to change an image when the mouse rolls over it.

Page 116: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

116

Addressing Objects

• In order to affect objects, JavaScript must have a way of addressing (naming) them.

• JavaScript uses a “dot scheme” (parts of the web page are addressed using certain terms with periods/dots in between).

Page 117: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

117

Addressing Objects

• For example, a graphic on a web page might be window.document.button or window.document.images[1]

• The largest part (window) is first, then a subset of window (document), and finally a subset of document (the image named “button”).

Page 118: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

118

Properties

• Objects on the screen often have properties (attributes) that can be addressed by JavaScript.

• For example, each image has a source.

• A web page document may have a background color.

Page 119: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

119

Properties

• Here are some “dot” addresses: image source (image place named M) window.document.M.src=“me.gif” image source (2nd image on the page)

window.document.images[2].src=“me.gif”

web page background color:

window.document.bgcolor.value=“blue”

Page 120: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

120

Example - The Status Bar

• JavaScript can be used to put text into the status bar.

• For example, a message can be placed in the status bar when the mouse moves over images.

Page 121: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

121

Example - The Status Bar

• The “dot address” of the status bar is window.status (it doesn’t have anything to do with the web page document, so the term document is not included).

Page 122: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

122

Example - The Status Bar

• Here is the code to add to an IMG tag to put text into the status bar:

onMouseOver=“window.status=‘HI!’”

• Notice that the entire instruction (from window.status to the end is in quotes (“).

• The message itself (HI!) is inside single quotes (‘).

Page 123: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

123

Example - The Status Bar

• The IMG tag might look like this (name of image file is “hello.jpg”)

<IMG src=”hello.jpg” onMouseOver=“window.status=‘HI!’”>

• Other choices for images are onClick (if you click on the image) and onMouseOut (when you move the mouse away from the image).

Page 124: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

124

Example - Text in a Box

• Forms are used to put buttons and input boxes on the web page.

• The next JavaScript example will put a message in a text box.

• The message will depend on the time of day.

Page 125: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

125

Example - Text in a Box

• This page uses FORM tags for the box:

<form name="greet"><input type="text"

size="20”name="greetingbox"></form>

This results in a text box (20 characters long) called greetingbox:

Page 126: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

126

Example - Text in a Box

The dot address for the box is: document.greet.greetingbox.value

The box is called greetingbox. The box called greetingbox is in the form

called greet.The form called greet in in the current

web page document.value shows that something will be put

into the box.

Page 127: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

127

Example - Text in a Box

Here is the JavaScript code:

<script language="JavaScript">currentTime=new Date();if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!"else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good

afternoon!"else document.greet.greetingbox.value="Good

evening!"</script>

Page 128: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

128

Example - Text in a Box

The SCRIPT tags begin and end the JavaScript:<script language="JavaScript">

currentTime=new Date();if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!"else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good

afternoon!"else document.greet.greetingbox.value="Good

evening!"</script>

Page 129: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

129

Example - Text in a Box

new Date() puts the current time/date (from your computer) into the variable currentTime:

<script language="JavaScript">currentTime=new Date();if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!"else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good afternoon!"else document.greet.greetingbox.value="Good

evening!"</script>

Page 130: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

130

Example - Text in a Box

Look at the structure of the IF statements:if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!"else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good

afternoon!"else document.greet.greetingbox.value="Good

evening!”

The computer must make a decision about the message, depending on the hour (12=noon, 17=5 pm). currentTime.getHours() contains the hour information (originally from new Date() )

Page 131: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

131

Example - Text in a Box

JavaScript IF statements look like this: IF (condition) instructions

The condition usually contains == (is equal to) or < (less than) or > (greater than).

If the condition is true, the instructions are carried out.

If the condition is false, the program goes to the next line without performing the instructions.

Page 132: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

132

Example - Text in a Box

In this case there are three choices:The hour is < 12 (before noon) - Good

morning!The hour is between 12 and 17 (noon and 5

pm) - Good afternoon!The hour is > 17 (after 5 pm) - Good evening!

Using IF, ELSEIF and ELSE lets the computer make the choice among these three options.

Page 133: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

133

Example - Text in a Box

• If you have looked at the HTML code for this example, you will see something very strange.

• The JavaScript is in the BODY section, not the HEAD.

Page 134: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

134

Example - Text in a Box

• The reason for this difference is that computer must be instructed to start the JavaScript.

• In past examples, we have clicked buttons to start the JavaScript instructions.

• This time, the instructions start automatically when the browser reaches that part of the HTML.

Page 135: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

135

Self Check – Example Questions

• True or false - all programming languages are object-oriented.

True False

Page 136: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

136

Self Check - Example Questions

• True or false - all programming langauges are object-oriented.

True False

{most current languages are object- oriented, but older languages like BASIC are not}

Page 137: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

137

Self Check - Example Questions

• In order to address objects on the screen, object-oriented languages use:

Pixel addresses (form top, from left) Dot addresses (e.g., window.status) They cannot address objects.

Page 138: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

138

Self Check - Example Questions

• In order to address objects on the screen, object-oriented languages use:

Pixel addresses (form top, from left) Dot addresses (e.g., window.status) They cannot address objects.

Page 139: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

139

Self Check - Example Questions

• The dot address of the source of an “image place” called M1 would be:

window.document.src. M1 window.document.M1.src document.M1.src

Page 140: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

140

Self Check - Example Questions

• The dot address of the source of an “image place” called M1 would be:

window.document.src. M1 window.document.M1.src document.M1.src

window may be deleted when the address refers to the web page document.

Page 141: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

141

Self Check - Example Questions

• The dot address of a text box called B in a form called MYFORM would be:

window.document.B.MYFORM window.document.MYFORM.B

Page 142: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

142

Self Check - Example Questions

• The dot address of a text box called B in a form called MYFORM would be:

window.document.B.MYFORM window.document.MYFORM.B

Page 143: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

143

Self Check - Example Questions

• The code to put “HI” into a box called B in a form called MYFORM would be:

window.document.MYFORM.B=“HI” window.document.MYFORM.B.src=“HI” document.MYFORM.B.value=“HI”

Page 144: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

144

Self Check - Example Questions

• The code to put “HI” into a box called B in a form called MYFORM would be:

window.document.MYFORM.B=“HI” window.document.MYFORM.B.src=“HI” document.MYFORM.B.value=“HI”

Page 145: HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page

145

End of Review