This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.

John McSweeney - picture detail

John McSweeney

May 9, 2008, 3:41 pm

M150 Data, Computing and Information

Event-Driven Programming with JavaScript

 

This question is by far the most difficult question in this series. It tests your knowledge of:

  • Event-driven programming
  • JavaScript Date objects and methods
  • Functions
  • Boolean conditions
  • Constructing HTML forms
  • Branching

Q11.
The image below is a screenshot of a HTML form that requests input from a user. On submitting the form, the user receives an appropriate message. Rather than describe in detail what is needed, I will ask you to download and save the HTML file (right click - Save Target As) and try out the form for yourself.

Having done this, I want to you to write your own program, which must replicate the behaviour of my program. Of course you could simply view the source code, but that would defeat the object of the exercise (no pun intended).

There are a number of hints that I could provide, but that would detract from the "experience". You will need to do some research; Unit 8 Section 4 and Unit 9 Section 4 will be very helpful. I am going to ask you to write your program for Netscape and IE. Consequently, you need to be aware that Netscape does something very odd when getting the year from a Date object. It deducts 1900 from the year, so the year returned from a Date object representing some date in 2004 is 104.
(Note that this exercise was originally written in 2004, hence the output given in the screenshot below.)
My program will run correctly under Netscape and IE (I have also tested it on Mozilla Firefox). It employs some browser detection code in order to execute selective code. You might also wish to do a Web search in order to discover how to use the navigator property of a browser window.

To make life easier, I have not asked for any data validation. Therefore you can assume that the user enters valid dates and checks one of the radio buttons.

Sample input and output for the form

 

Previous page « Objects