Nathan Sokalski
2009-10-11 02:21:24 UTC
I have a page that is giving me the following error message:
Error: Object required
I have determined, after some experimenting, that this is due to the fact
that the HTML has not been parsed when the script is called. Here are two of
the variations of the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function SlideIntoView(id)
{window.alert(document.getElementById(id).id);}
SlideIntoView('divContentArea');
</script>
</head>
<body>
<div id="divContentArea"></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function SlideIntoView(id)
{window.alert(document.getElementById(id).id);}
</script>
</head>
<body onload="SlideIntoView('divContentArea');">
<div id="divContentArea"></div>
</body>
</html>
The only difference between the two pages is that the statement
SlideIntoView('divContentArea');
Is located inside the script tag in the first version, and in the body's
onload eventhandler in the second. The first gives the Object required error
message, but the second works fine. However, with all the code that
sometimes needs called right away, and that gets added dynamically in
server-side development, it would be unrealistic to need to put it all in
onload. I have never needed to worry about this before (I am currently using
IE7). How can I make sure the browser has parsed the HTML before calling the
code? Any help would be appreciated. Thanks.
Error: Object required
I have determined, after some experimenting, that this is due to the fact
that the HTML has not been parsed when the script is called. Here are two of
the variations of the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function SlideIntoView(id)
{window.alert(document.getElementById(id).id);}
SlideIntoView('divContentArea');
</script>
</head>
<body>
<div id="divContentArea"></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function SlideIntoView(id)
{window.alert(document.getElementById(id).id);}
</script>
</head>
<body onload="SlideIntoView('divContentArea');">
<div id="divContentArea"></div>
</body>
</html>
The only difference between the two pages is that the statement
SlideIntoView('divContentArea');
Is located inside the script tag in the first version, and in the body's
onload eventhandler in the second. The first gives the Object required error
message, but the second works fine. However, with all the code that
sometimes needs called right away, and that gets added dynamically in
server-side development, it would be unrealistic to need to put it all in
onload. I have never needed to worry about this before (I am currently using
IE7). How can I make sure the browser has parsed the HTML before calling the
code? Any help would be appreciated. Thanks.
--
Nathan Sokalski
***@hotmail.com
http://www.nathansokalski.com/
Nathan Sokalski
***@hotmail.com
http://www.nathansokalski.com/