Cross Browser getObject()
Odds are, any time you are using javascript, you are using it to access/modify elements and their properties on a page.
I was getting tired of having to check each time whether the browser could use the getElementById() function or if it had to use the document.all method. So I wrote a small little piece of code that you can use on your site in order to alleviate this problem.
function getObject(el) {
return document.getElementById ? document.getElementById(el) : document.all[el];
}
I would rather use the getElementById function, so that is why I check for that first. The only browsers that are still in use that do not have the getElementById function are older versions of Internet Explorer, which can use the document.all function. Of course, you can always switch the text around to check for the document.all function first. To do so, use the following code:
function getObject(el) {
return document.all ? document.all[el] : document.getElementById(el);
}
To use the function, you only have to do the following (if your element was labeled 'Test')
var ElementValue = getObject('Test').value;
NOTE: Be sure to include the 'id' attribute on your element in order for this to work in all browsers.