The DOM

Code Snippet

Looking at the JavaScript and HTML below, answer the questions in the quiz to the right. Through the magic of JavaScript, your quiz will be automatically scored as you take it.

   <script type="text/javascript">

   function validateIt()
   {
      fName = document.forms["myForm"].firstName;
      if (fName.value == "")
      {
         alert("Enter your name below.");
      }
   }

   </script>
</head>
<body>
<form name="myForm"
   onsubmit="validateIt()">
   
   <input type="text" name="firstName">
   First Name<br>
   
   <input type="submit" value="Submit">
</form>

Quiz

The value of fName is a/an:

Variable
Property
Object
String

When the user clicks the “Submit” button:

The form will be submitted
The alert() method will be called.
The validateIt() function will be called.
For the love of God, how am I supposed to know?

Assuming the user has left the text input blank, the validateIt() function will:

pop-up an alert telling the user to enter her/his name.
fill in the correct name for the user based on a previously saved cookie.
fill in the default value of “Andrew”.
try to make the user feel better by offering words of encouragement.



And now, back to our agenda!