Lab 9: JavaScript
What You Will Do Today
- Insert automated document information into the page.
- Display a link mouseover message in the status bar.
- Change a linked image with a mouseover.
- Link to other pages using a dropdown menu.
- Validate a form using a function.
Setup
- Look at the JavaScript examples in
/home/umu/WebResources/javascript/examples/.
- Create a folder named weblab9
in your folder.
- Open a new page in Mozilla Composer.
- The page title and a Heading 1 should both be Web Lab 9 by Your Name.
- Type Document Information and format as Heading 2.
- Add a script tag of type text/javascript.
- Use a writeln statement and the Date() function to display the time:
- Use writeln statements to display the following
document properties, one per
line:
- foreground and background colour, title, URL, date of last modification,
and referrer.
- E.g.
- Save and test in a browser.
Mouseover Status Message
- Type Mouseover Link and format as Heading 2.
- Type UMU and link to the UMU
home page.
- Add the following attributes to the link:
-
onmouseover="window.status='Uganda Martyrs University Intraweb Home';
return true;"
onmouseout="window.status=''; return true;"
- Save and test in a browser.
- Type Mouseover Image and format as Heading 2.
- Copy the files awake.gif and stop.gif into your weblab9 folder.
- Insert the image stop.gif into the page.
- Link the image to
javascript:alert("Meow!")
- Add an attribute
name="mypic"
to the image tag.
- Add the following attributes to the link:
-
onmouseover="mypic.src='awake.gif'"
onmouseout="mypic.src='stop.gif'"
- Save and test in a browser by moving the mouse over the image, then
clicking it.
- Type Links Menu and format as Heading 2.
- Add a select tag with the attribute
onchange="document.URL=options[selectedIndex].value"
.
- Add an option
<option value="javascript:alert('Please select
a site.')">Select a Site
- Add an option for UMU, e.g.
<option value="http://home.umu.ac.ug/">Uganda Martyrs University
- Add an option for three other links.
- Save and test.
- Type Form Validation and format as Heading 2.
- Create a form with attributes
name=myform onsubmit="return
validate(myform)"
- Add three elements, each on its own line:
- Text indicating "Please enter your e-mail address."
- A text field named email of width 40.
- A submit button labeled "Submit Query."
- Add a script tag in the head of the document.
- Add a function named validate which has one
argument, myform.
- Test if myform.email.value is equal to ""
(the empty string).
- If so, print an alert "Please enter your e-mail address." and return
false.
- Otherwise print an alert "Form submitted with e-mail address " +
myform.email.value and return true.
- Save and test.
Submit the Assignment
- Use Ark to compress your weblab9 folder to weblab9.zip.
- Send the weblab9.zip file as an e-mail attachment to gvogl@umu.ac.ug with subject line web lab
9.