Digging Deeper into JavaScript

advertisement
Digging Deeper into JavaScript
(or Do I Really Understand its Code?)
We are going to start by creating a blank web page that with the following code:
<html>
<body>
<head><title>JavaScript Lab</title></head>
<script language="JavaScript">
</script>
</body>
</html>
Step 1: Use the document object to write out the HTML code to display your name and
what class this is.
Step 2: Create a for loop to write the information out in Step 1, ten times.
Step 3: Place your JavaScript code inside a function called displayName().
Step 4: Setup the webpage so that instead of the JavaScript code being embedded directly
in it, it is instead its own file.
Step 5: Add a form to your webpage so that you can enter in a value and use the
onchange attribute to trigger your JavaScript function displayName().
Step 6: Have your JavaScript code read the value from the form (the document object
will help you do this) and use that to determine how many times to loop.
Step 7: Add an if statement to your code by using the isNaN function (see Example 2) in
the JavaScript code to ensure you are getting a number. Also, check to make sure it is
positive in value.
Step 8: Try using confirm() and prompt() (page 201 of the JavaScript book) with your
JavaScript code for when a wrong value is put into the form.
JavaScript Project – Part A
(Note: There will be a Part B Due at the Same Time.)
Due Oct 8th
Part 1: Create a Project 3 page and link your homepage to it. Again, set it up using
frames with the left side containing links to pages and the right side acting as the display
area for those pages.
Part 2: Make a copy of your form page from Project 1. Add JavaScript to the page so
that when you click the submit button all values from the form are retrieved and
displayed using the confirm() function. (Note: If you decided to separate the JavaScript
from the webpage make sure you provide a link to the JavaScript code.)
Download