The JavaScript Object hierarchy

Finding your way around

The JavaScript Object hierarchy is a structured set of programmable elements that Web pages are made up of. By learning this structure, you can use JavaScript to control the appearance and behavior of elements on your Web pages.

Try to understand the code and predict what will happen when you push the different buttons. This little example will serve as an indicator of your understanding of JavaScript up to this point.

Name:
E-Mail:

<SCRIPT>

function writeField() {
    var fld = "Yo, what's up!";
    document.forms[1].elements[0].value = fld;
}

function returnValue(expression) {
    var fld = expression;
    return fld;
}

function changeBtn(btn) {
    if (
btn.value == 'Push Me') btn.value = 'PUSH ME';
    else btn.value = 'Push Me';'
}

</SCRIPT>

<FORM>
    
<INPUT TYPE="text" VALUE="bla bla bla">
     <INPUT TYPE="button" VALUE="Write"
       onClick="document.forms[1].Name.value='Yo!';">
     <INPUT TYPE="button" VALUE="writeField"
       onClick
="writeField();">
     <INPUT TYPE="button" VALUE="returnValue"
       onClick="document.myForm.elements[1].value= returnValue('frank@sislands.com');">
</FORM>

<FORM  NAME="myForm">
     Name: <INPUT TYPE="text" NAME="Name" VALUE>
     E-Mail: <INPUT TYPE="text" VALUE>
     <INPUT TYPE="button" VALUE="Push Me"
       onClick
="changeBtn(this);">
</FORM>