Lesson 7

Objects and Events


Basic Form components -- inputs, buttons, textareas, selections, radio buttons, checkboxes, and responding to associated events.


Anatomy of a form element:

1. Though some browsers might recognize an <input> that is not inside form tags, some won't. So form elements should appear inside form tags:

<form>
<input>
</form>
or 
<form>
<textarea cols=24 rows=4></textarea>
</form>

2. Since we will be reading from, or writing to form elements, we have to figure out some way to refer to them.

referring to an element by name
<form>
<input name="IamNamedQ" onclick="alert(IamNamedQ.name)">
</form>
 

 writing to an element using its position within the elements[] array of the form

<form>
<input onclick="elements[0].value='this is the 0th element';">
</form>
 

referring to an element as 'this'

<form>
<input name="NamedZ" onclick="alert(this.name)">
</form>

3. In addition to the name attribute of a form element, other attributes are worthy of investigation:

4. Various different sorts of events may be generated from a form element.