


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























-^ The functions we’ve seen so far have been functions which required noparameters. In other words, we did not need to send any information to thefunction in order for the function to accomplish its task. (Recall that whena function is invoked (called) it simply performs the task it was designed toaccomplish.)•^ In Practice Problem #26 the function printed Tiffany’s name. Suppose thatwe wanted the function to be able to print any visitor’s name.
To
accomplish this, we would need to ask the user to enter their name andthen send their name as a parameter to the function.• Just like the variables we’ve already seen in JavaScript, a parameter is alsoa variable, but this variable belongs only to the function in which it isdefined.• Let’s rewrite Practice Problem #26 using a function with a parameter inwhich we will send the function the visitor’s name.
More On JavaScript Functions
More On JavaScript Functions
^ JavaScript
functions
with^ parameters
function
writeVisitorName(name)
document.write("
"^ +^ name
**} ** Thanks^ for
using^ JavaScript
^
/*^ ^ */
More On JavaScript Functions
Creating A Slide Show Using JavaScript /* The text^ captions
are^ stored
in^ another
array.*/
var^ myCaptions
=^ new^ Array(); myCaptions[1]
=^ "Team^
USA^ -^ Pan^
Am^ Gold^ Medalists.";
myCaptions[2]
=^ "Jennie
Finch^ -^ Team
USA^ pitcher.";
myCaptions[3]
=^ "Jessica
Mendosa^
-^ Team^ USA -^ right^ fielder.";
myCaptions[4]
=^ "Cat^ Osterman
-^ Team^ USA
pitcher.";
myCaptions[5]
=^ "Caitlin
Lowe^ -^ Team
USA^ and^
Arizona^ Wildcat.";
myCaptions[6]
=^ "Taryne
Mowatt^ -^
University
of^ Arizona
Wildcats^
-^ pitcher.";
myCaptions[6]
Female^ Athlete
of^ the^ Year
myCaptions[7]
=^ "Lovie
Jung^ -^ Team
USA^ -^ Sliding
int^ 2nd^
base^ during
2007 World
Cup.";
myCaptions[8]
=^ "Three
great^ pitchers:
Jennie^ Finch,
Alica^ Hollowell,
and^ Cat^ Osterman.";
var^ slidenumber
var^ totalslides
=^ mySlides.length
function^
showSlide(direction){if (direction^ ==
"next"){ (slidenumber
==^ totalslides)
?^ slidenumber
=^1 :^ slidenumber++;
}else{(slidenumber
slidenumber
=^ totalslides
:^ slidenumber--;
} if^ (document.images){document.slideframe.src
=^ mySlides[slidenumber].src; document.slidecontrols.caption.value
=^ myCaptions[slidenumber];
document.slidecontrols.currentslide.value
=^ slidenumber;
} }
Creating A Slide Show Using JavaScript Softball^ Images
2006-2007
^
-^ The
fo the document includes an image called
slideframe
and a from
called^ slidecontrols
.^ Wihtin the form is a textarea called caption set to display 2 rows and 50 characters (columns) of text.
An initial text string informs
the visitor that the slide show begins with a picture of the 2007 Pan Am gold medalteam from the USA.• The form includes two buttons, the first button calls the
showSlide()
function
and sends it the value
previous
.^ The second button calls the
showSlide()
function and sends it the value
next.
-^ The
showSlide()
function in the
takes the value of the parameter it
receives (either
previous
or^ next
) and places it in a local (temporary) variable
named^ direction
. If^ direction
has a value of next, the function looks to see
whether the current slide number (stored in the global variable
slidenumber
) is
the last slide in the show.
If it is,
slidenumber
is reset to 1, Otherwise,
slidenumber
is incremented by 1. If
direction
is^ previous
, the function
checks to see if the current slide number is the first slide in the show.
If it is,
slidenumber
is set to the total number of slides. Otherwise,
slidenumber
is
How The Slide Show Script Worksdecremented by 1. if (direction == "next"){
-^ Finally, the
showSlide()
function checks to make sure that
the browser supports the
images array.
It then uses the
current value of
slidenumber
to determine which element
of the^
mySlides
array and corresponding element of the myCaptions
array to display.
The^ slidenumber
is also
displayed in the text field called
currentslide
so that the
visitor will see the number of the current slide.• This slide show technique is useful for building pages whereyou want the visitor to proceed through a series of images byclicking
buttons.
Corporate
presentations,
travel
logs,
How The Slide Show Script Worksinstructional demonstrations are just some of the possibleapplications.
-^ The table heading element
^ is used to label the rows and columns of
a table.^
This element is an optional element for tables, as some tables do not require headings.
In most browsers the
^ element automatically
centers the content of the element within the table’s cell and makes the textbold.• The main body of a table is made up of rows and columns, like a matrix.In XHTML, you construct your tables one row at a time. Each row beginswith an opening table row
^
tag.^ Each column within that row
contains the open and end tags for the table data
^ element. After the
last^
element is closed for the last column, the row ends with the ending^
tag.^ Shown below is the definition for a row that contains three columns.
XHTML Tables
column
1 ^ column
2 ^ column
3
XHTML Table –Example 1^ © Mark Llewellyn
Table^ Example
in^ XHTML Our
First^ Table
A
Simple^ Table
of^ Columns
and^ Rows
Column
1 Column
2 Column
3
Column
1 ^
Row^ 2 Column
2 ^
Row^ 2 Column
3 ^
Row^ 2
Column
1 ^
Row^ 3 Column
2 ^
Row^ 3 Column
3 ^
Row^ 3