Javascript Reference Guide

 
 
This guide contains useful Javascript tips.







DOM.



Information
The Document Object Model (DOM) is a set of objects for example images, forms, layers etc. that the Web browser creates when a page is loaded. The DOM objects are structured as a tree where the top would be called a document and the branches are called the nodes. All html tags are thus called nodes even the atributes and the values of these attributes.

More information about XML DOM can be found at: Quick reference
  • document - refers to the actual page and content for that page, it is the top level of all and everything else is underneath it. For example: first comes document followed by <HTML> followed by <HEAD> etc.

  • To access form objects:

    Method 1Method 2
    document.formName.inputNamedocument.forms[i].inputName
    document.formName.elements[i]document.forms[i].elements[i]
    Note: i starts with 0
            <form name="myForm1">
                <input type="text" name="myTextBox1" />
                <input type="text" name="myTextBox2" />
            </form>
            <form name="myForm2">
                <input type="text" name="myTextBox3" />
                <input type="text" name="myTextBox4" />
            </form>		 
    		
    To access <input type="text" name="myTextBox4" /> and method 1 is used:
    document.myForm2.elements[1]

  • To access layer objects:

    Methods
    document.all[layerID]
    document.all(layerID)
    document.all.layerID
    layerID
    Note: i starts with 0
            <form name="myForm1">
                <input type="text" name="myTextBox1" />
                <input type="text" name="myTextBox2" />
            </form>
            <form name="myForm2">
                <input type="text" name="myTextBox3" />
                <input type="text" name="myTextBox4" />
            </form>		 
    		
    To access <input type="text" name="myTextBox4" /> and method 1 is used:
    document.myForm2.elements[1]

Code
    <script type="text/javascript" language="JavaScript">
    document.write("You are using browser: " + navigator.appName + ".");
    </script>
	
Result