Tutorial 3: Feedback Using Alert Boxes

 

 

The following tutorial presupposes that you have some familiarity with HTML authoring.
This an example of an exercise that provides immediate feedback by means of alert boxes to the user's answer in an input text field ("blank").
This exercise presents a dialogue, but it can be adapted for other grammatical or communicational goals.
Click here to see the finished product: template3.html

 

Some points to remember:

JavaScript is case sensitive, so you will have to be consistent using lower case or capital letter when naming your functions or calling values from forms. That applies also to accented words.


  1. Remember that all the functions of the JavaScript code must be placed between the <HEAD></HEAD> tags of your HTML document.

  2. Like any other JavaScript coding, start by inserting these two lines right after the <HEAD> tag:

    <SCRIPT LANGUAGE = "JavaScript">
    <!--

  3. This script has only one type of function which generates the feedback for the answers entered by the user in the text field ("blank").

  4. The naming of the functions is pretty much arbitrary: checkIt() takes care of the first question, and checkIt2() implements the feedback for the second question.

  5. Let's examine the first one, checkIt():
  6. Finally, let's see how this type of function is called from the button and image of the HTML. This template uses two clickable objects: a button labeled "1." and an image .

    See how the event onClick is incorporated inside the tags of the button to call the first function of the script:

    <INPUT TYPE = "button" NAME = "click1" VALUE = "1." onClick = "checkIt()">

    For the image we have the following tag:

    <A HREF = "Javascript:checkIt2()"><IMG SRC = "../Colby/images/checkmrk1.gif" ALIGN = "top" BORDER = "0" HSPACE = "3" WIDTH = "18" HEIGHT = "17"></A>

    In this case we make the image clickable by placing it within the <A HREF></A> tags. The "link" for the image is now the JavaScript coding "javascript"checkIt2()", that is, the calling of the second function of the script. So, when the user clicks on the image, the second function gets implemented.

  7. Now you can close your script with the customary lines:

    // -->
    </SCRIPT>
    </HEAD>