How to test for the Javascript DOM?

Written by Riaan Pieterse

Continued from page 1

if (isIE4){

return document.all[documentID];

}else if(isIE6){

return document.getElementById(documentID);

}else if (isNS4){

return document.layers[documentID];

}else if (isNS6){

return document.getElementById(documentID);



The above function comprimises by usingrepparttar typical test defined earlier to identify our browser DOM, and returnsrepparttar 105593 object identified by its ID / NAME pair. So whenever you need to do something to an object, this approach requires that you callrepparttar 105594 getDOMObeject () function. For example, repparttar 105595 following will setrepparttar 105596 value attribute of a hypothetical text box to 'test value'.

getDOMObject('txtMyTextBoxID').value = "Test Value";

The value of this approach comes torepparttar 105597 front in scripts where you need to access multiple objects in your document. For example:

getDOMObject('txtMyTextBoxID1').value = "Test Value 1";

getDOMObject('txtMyTextBoxID2').value = "Test Value 2";

getDOMObject('txtMyTextBoxID3').value = "Test Value 3";

getDOMObject('txtMyTextBoxID4').value = "Test Value 4";

getDOMObject('txtMyTextBoxID5').value = "Test Value 5";

getDOMObject('txtMyTextBoxID6').value = "Test Value 6";

Looks like a lot less work, doesn't it?


Riaan Pieterse is the CEO and founder of Kerberos Internet Services CC, South Africa. Having spent a number of years conducting various consulting assignments in the Far East, Middle East, Africa and Europe to businesses and governments alike, Riaan has a solid understanding of the business and technology issues in today's market. For more information visit or


Written by

Continued from page 1

    <Back to Page 1 © 2005
Terms of Use