rendered paste bodyError: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost/whitelynx/cs.fredonia.edu/search.js :: init :: line 113" data: no]
Code:
// Cross-browser element retrieval function, courtesy of www.quirksmode.org.
function getObj (name)
{
if (document.getElementById)
{
this.obj = document.getElementById (name);
this.style = document.getElementById (name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = getObjNN4 (document, name);
this.style = this.obj;
}
}
function getObjNN4 (obj, name)
{
var x = obj.layers;
var foundLayer;
for (var i=0; i < x.length; i++)
{
if (x[i].id == name)
{
foundLayer = x[i];
}
else if (x[i].layers.length)
{
var tmp = getObjNN4 (x[i], name);
}
if (tmp)
{
foundLayer = tmp;
}
}
return foundLayer;
}
function init ()
{
var searchbox = new getObj ('SearchBox');
var searchform = new getObj ('SearchForm');
var searchbutton = new getObj ('SearchButton');
alert ("ooB!");
if (searchform.offsetWidth)
{
alert ("offsetWidth");
}
else if (searchform.currentStyle)
{
alert ("currentStyle");
var newWidth = parseInt (searchform.currentStyle['width']);
newWidth -= parseInt (searchbutton.currentStyle['width']);
}
else if (window.getComputedStyle)
{
alert ("getComputedStyle");
alert (document.defaultView.getComputedStyle (searchform, null).getPropertyValue ('width'));
alert ("Boo!");
var newWidth = parseInt (document.defaultView.getComputedStyle (searchform, null).getPropertyValue ('width'));
newWidth -= parseInt (document.defaultView.getComputedStyle (searchbutton, null).getPropertyValue ('width'));
}
else
{
alert ("none");
}
alert ("ooB!");
searchbox.style.width = newWidth;
focusSearchForm ();
}