views:

49

answers:

3

IE continues to give me an error on the next-to-last line stating "Object required". I am not sure where the issue would be. Any advice?

    function showdiv()
{
document.getElementById("dialogue").style.display = "";
document.getElementById("screen").style.display = "";
document.getElementById("screen").style.width = getBrowserWidth();
}
function hidediv(opt){
if(opt=="agree"){
document.Annexation.checkbox.checked = true;
document.getElementById("dialogue").style.display = "none";
document.getElementById("dialogue").style.display = "none";
document.getElementById("screen").style.display = "none";
}else{
document.getElementById("dialogue").style.display = "none";
document.getElementById("screen").style.display = "none";
}}

window.onscroll = scrollEvent;
function scrollEvent() {
var y;
if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
y=document.documentElement.scrollTop; 
else if (document.documentElement && document.documentElement.scrollTop){
// IE6 +4.01 and user has scrolled
y=document.documentElement.scrollTop;
}
else if (document.body && document.body.scrollTop){
// IE5 or DTD 3.2
y=document.body.scrollTop;
}
document.getElementById("screen").style.top = y+"px";
} 
A: 

One of the following probably returns null:

document.getElementById("dialogue")
document.getElementById("screen")
document.Annexation
document.Annexation.checkbox

or getBrowserWidth is not defined.

David Hedlund
This script is part of a main.js file that encompasses a whole site. On this specific page, "dialogue" nor "screen" are present. I'm assuming this is what would cause them to return as null?
Slevin
@Slevin: if `showdiv` or `scrollEvent` or `hidediv` are called, and `screen` or `dialogue` does not exist, that will cause an error, yes. you can insert, as first line in each of these functions, the following `if(!document.getElementById('dialogue') || !document.getElementById('screen')) { return; }` which will abort the function when any of the DIVs don't exist
David Hedlund
David, That did the trick. Thanks a lot!
Slevin
A: 

document.getElementById("screen") Is undefined. Add the following code:

if( !document.getElementById("screen") ) alert( "Spara was right." );

and it will tell you if that is the case or not.

Sparafusile
Spara, I added that line above the document.getElementById("screen") and it did return the alert (which made me laugh by the way). How can I resolve this? Can I set that "screen" as a variable and assign it to be 0 or something?
Slevin
A: 

What does Annexation standar for in document.Annexation.checkbox.checked = true;

You have 2 ways to select a checkbox. One is assigning a name value for the tag of checkbox.

<input type="checkbox"  name="ck" />

document.getElementsByName("ck")[0].checked = true; to make the checkbox checked.

Another method is assigning an id for the tag of checkbox.

<input type="checkbox"  id="ck" />

document.getElementById("ck").checked = true; to make the checkbox checked.

unigg
Unigg, Thanks for the insight. Unfortunately, this is not code I have written so I am still learning my way around everything and the way my predecessor had organized things.
Slevin