View Full Version : newbie. 'object required' message failure to understand
Roy Gardiner
07-21-2004, 05:53 PM
<body onLoad="legend()"> 1st line of function 'legend' document.getElementById('body').style['backgroundColor'] = 'red' html snippet<div id="body"> gives me the error 'object required' when run on my home machine, ie6. My code seems to run as designed thereafter; at work it runs without error (sorry, can't give ie version).
Any insight would be helpful :confused: no doubt once again a very basic question, sorry.
The whole thing is 200 lines so I guess too large to paste here? I'll create & paste a small version if the answer isn't obvious.
Willy Duitt
07-21-2004, 06:46 PM
Try changing the division id from body to something else....
Roy Gardiner
07-21-2004, 07:03 PM
Try changing the division id from body to something else.... Thanks, tried that, no effect. Are there reserved words of this kind in the HTML?
sad69
07-21-2004, 07:56 PM
Instead of:
<body onload="legend()">
Try:
<body>
...
<script>
legend();
</script>
</body>
I'm thinking that the div hasn't loaded yet, so it can't find that div..
Sadiq.
Willy Duitt
07-21-2004, 08:06 PM
It is much easier for me to read code if it is all together in one block and not spread as little snippets hither and yon...
Anyway, after looking at your snippets again.
You are referring to the backgroundColor incorrectly..
It should be: style.backgroundColor
Not: style['backgroundColor']
.....Willy
Roy Gardiner
07-21-2004, 08:22 PM
It is much easier for me to read code if it is all together in one block and not spread as little snippets hither and yon... Well the whole thing is 200 or so lines, but I'll create a smaller version if needed, as I said at the start.Anyway, after looking at your snippets again. You are referring to the backgroundColor incorrectly..
It should be: style.backgroundColor
Not: style['backgroundColor'] That's not it either, I'm afraid, I tested that before posting. The square bracket feature I particularly want, because eventually it's going to be a variable.
Roy Gardiner
07-21-2004, 08:24 PM
Instead of:
<body onload="legend()">
Try:
<body>
...
<script>
legend();
</script>
</body>
I'm thinking that the div hasn't loaded yet, so it can't find that div..
Sadiq.Thanks, tried that, again no effect.
sad69
07-21-2004, 08:35 PM
It must be another issue altogether, as I just created this test file and it executes just fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function legend() {
document.getElementById('body').style['backgroundColor'] = 'red';
}
</script>
</head>
<body onload="legend()">
<div id="body">
lala
</div>
</body>
</html>
I'm running IE6 on XP.
Sadiq.
Roy Gardiner
07-21-2004, 09:03 PM
It must be another issue altogether, as I just created this test file and it executes just fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function legend() {
document.getElementById('body').style['backgroundColor'] = 'red';
}
</script>
</head>
<body onload="legend()">
<div id="body">
lala
</div>
</body>
</html>
I'm running IE6 on XP.
Sadiq. Aha, OK, looks like I'm looking in the wrong place; as I said, it works fine for me at work, not at home.
I'll try to recreate the error in a small example to see if others here can reproduce it.
Thanks for your help!
Roy
ps. and your example runs fine on my machine, too. If I could have a pound for every time I've looked in the wrong place...
Roy Gardiner
07-22-2004, 06:53 PM
Sad69, Willy Duitt, Thanks for your help.
Putting up code snippets broke one of my rules, which is always to create a small but complete example which demonstrates the query. As Willy correctly and gently pointed out :thumbsup: . Sadiq did my work for me which is a :thumbsup: for him and a double :( to me.
When I went to re-create his example by cutting away at my original code, I found the error.
Gentlemen, my apologies for wasting your time, especially as I know better (which makes it worse!), and once again my thanks for your patience and help.
Roy
Willy Duitt
07-22-2004, 06:55 PM
Cheers;
Glad to hear you worked it out....
.....Willy
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.