COMP1710 : Laboratory 7 : JavaScript

Version of the lab from 2004 (detailed description of a validated form)

Correction : Some tips

1. Objectives

This week lab is about Javascript. The tasks is to adapt some existing scripts to different situation : set up a rollover picture, check the content of a form, switch from one CSS to another ...

If you want to be ready for it, read (and experiment with) the text book "The Web Wizard's Guide to JavaScript"

Additional reference :

2. Tasks

2.0 Task0

Make sure you have read the text book, or the online slides

As usual now, create a directory named LABn_Uxxxxxxx  where you will put today work. Include an index.html file that will link directly or indirectly to all the html pages you will create. There should be a link to that page in all the pages you will create. There should be your name and a mailto link to your email at the bottom of all your pages.

Important : you should make sure to include a special page named source.html or log.html with the list of media you used in your lab, with the type of modification you have done. Please read the rule about borrowing data in the context of COMP1710 labs and assignment

2.1 Task1 Write a Form to generate the HTML code for a link

Create a form that will generate the code for an HTML link with some control and/or reformatting of fields

Minimum set of elements in the form, with the validation scheme for each element

Hint: http://escience.anu.edu.au/lecture/comp1710/HTML/linkTwoParts.en.html

Hint 2 : Start building an HTML page with a form and its fields and then ad some javascript functions and event handlers one by one.

Use 'alert' windows or HyperEdit software to debug your javascript code (HyperEdit allows you to display the content of a chosen variable)

A) A text field for the URL

Check that the field is filled, and that the URL has the following format :
protocol://serverName/something
where

Display a warning if there is an issue (with the explanation)
Delete any space (no need for a warning : just clean the field)

Hint: listing3.2

B) A text field for the link label (what is visible to the user)

Check that the field is filled
Display a warning if there is an issue (with the explanation)
Delete space at the beginning and the end

Hint: listing3.1 and ('while' loop + 'String' methods)

C) 3 text fields for the 'name', the 'id' and the 'target' attributes

Check that they contains only alphanumeric characters
Display a warning if there is an issue (with the explanation)
Delete any space.

Hint: listing3.3

D) A select Menu

That propose to encapsulate the link into a choice of   'nothing',  in a paragraph (between <p> and </p>), or as header of  level 1 to 6

Hint: listing3.6

E) A text area

It will contain the generated HTML code

F) An small image used as a button

When you move your mouse over it, the various fields are checked, and if everything is OK, the generated code is written/updated into the text area

G) A button that open a new window with the page pointed by the URL when you click on it

Function : let the user check the validity of the link by looking at the web site in a different window.
Hint :

http://escience.anu.edu.au/lecture/comp1710/HTML/linkTwoParts2.en.html

http://wps.aw.com/wps/media/objects/58/60015/overview/jsbasics.html (Build a page with document.write() part)

H) A button that rewrite the following <P> element with what the link will look like

The previous text area would display the HTML code, this action should display the interpreted HTML

Hint : listing5.1.inP.html

2.2 Task2

Create two web pages and use JavaScript to detect a KeyPress event. Yo uwill then be able to swicth between the two pages whenever the keyboard space bar is pressed.

Hint : look at almost any page from the lecture notes. Note that this code is a bit old and dirty. You would rather clean it or find a better solution.

2.3 Task3

There are "just" two compulsory task in this lab, in order to deal with different student experience with programming, but if you are confident , explore the 'extra work' part

3. Conclusion

This lab was an introduction to client side programming. You should be able to use Javascript in HTML pages to validate a form, or do other basic tasks, not presented in the lab, like image swapping (rollover), display of the date and time ...

4. Extra work

Prepare a web page and, at least, two different CSS for that page. Give a way to switch from one CSS to the other.

Hints:

5. Summary to get 3 marks for this lab session

This week, you may follow exactly the same process as previous weeks to upload your work, or chose to ftp to liskov to do so.

If there is an issue with partch, you may use iwaki instead.

N.B. : For more information about the uploading and access to partch/iwaki/liskov server, please consult

http://liskov.anu.edu.au/ and http://tsg/twiki/bin/view/Documentation/StudentSettingUpWebPages

> scp LAB7_U4032266.zip u4032266@partch.anu.edu.au:public_html
   The authenticity of host 'partch.anu.edu.au (150.203.24.13)' can't be established.
   RSA key fingerprint is c8:ad:18:32:da:37:6f:d5:72:ab:c9:8b:8e:e7:f2:59.
   Are you sure you want to continue connecting (yes/no)? yes
   Warning: Permanently added 'partch.anu.edu.au' (RSA) to the list of known hosts.
   u4032266@partch.anu.edu.au's password:  your passwd here 
   LAB7_U4032266.zip                        4% 344KB   13.7KB/s 09:46 ETA
   LAB7_U4032266.zip                      100% 8404KB   8.7KB/s   16:01                                                                                                                   100% 8404KB   8.7KB/s   16:01    

   >  ssh u4032266@partch.anu.edu.au
u4032266@partch.anu.edu.au's password:  your passwd here 

partch:~> cd public_html
partch:~/public_html> ls
 LAB7_U4032266.zip
partch:~/public_html> unzip LAB7_U4032266.zip
Archive:  LAB7_U4032266.zip
   creating: LAB7_U4032266/
   creating: LAB7_U4032266/testweb/
  inflating: LAB7_U4032266/testweb/back.gif  
  inflating: LAB7_U4032266/testweb/background.gif  
  inflating: LAB7_U4032266/testweb/forward.gif  
   creating: LAB7_U4032266/testweb/fullsize/
  inflating: LAB7_U4032266/testweb/fullsize/2004_04_17_10.02.20.jpg  
  .....
  >

Notes