JavaScript getElementById

getElementById() is a method of document object, it gets the tag element with the value "id" in its ID attribute.

To reference in a JS script to a HTML tag through its ID, use the following syntax:

    document.getElementById("id")

So even though the Internet Explorer JavaScript engine uses a mark-and-sweep
implementation, any COM objects that are accessed in JavaScript still use reference counting,
meaning circular references are still a problem when COM objects are involved. The following
simple example demonstrates a circular reference with a COM object:

var element = document.getElementById(“some_element”);
var myObject = new Object();
myObject.element = element;
element.someObject = myObject;

This example sets up a circular reference between a DOM element (element) and a native JavaScript
object (myObject). The myObject variable has a property called element that points to element,
and the element variable has a property called someObject that points back to myObject. Because
of this circular reference, the memory for the DOM element will never be reclaimed even if it is
removed from the page.

<script type="text/javascript">
function testEmpty(){
 var myTextField = document.getElementById('myTxt');
 if(myTxtField.value != "")
  alert("entered: " + myTxtField.value)
 else
  alert("please enter some text?")  
}
</script>
<input type='text' id='myTxt' />
<input type='button' onclick='testEmpty()' value='Checked' />

The argument that getElementById requires is the id of the HTML element you wish to utilize.