Thursday, March 31, 2011

Checking for the Existence of an Object

When using hidden fields, or generic form fields, as part of best practice it is advisable to check for the existence of the object on the page. 

Example

var Element = document.getElementById("page");

if (Element != null){ // Check object exists
                //Do something
}

Checking for the object on the page enables it to be reusable. It does not need to be on the given page your working with, to be part of your code.

No comments:

Post a Comment

Programming for the Web