October 27, 2021

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

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". Back in 2004, I asked students to write a program for Netscape and IE, which shows how times have changed. Now, in 2014, I have tested this in Firefox, hence the output below. But in 2004, Netscape did something very odd when getting the year from a Date object. It deducted 1900 from the year, so the year returned from a Date object representing some date in 2004 was 104.
So my program employs some browser detection code in order to execute selective code and hence 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


Next page » The continue statement Exchange Protocol

Previous page « Objects








Up to top of page