Connecting Tech Pros Worldwide Forums | Help | Site Map

Script works in Mozilla but not IE6 (latest versions)?

mark
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi i get an error on this line of my script. It works in mozilla but not IE6

Here is the error message

document[...] is null or not an object

Here is the function - also images for this button rollover are preloaded

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

function roll(img_name, img_src)
{
document[img_name].src = img_src;
}

//-->
</SCRIPT>

call function with this

onmouseover="roll('sub_but1', 'http://www.kidsoft.org.uk/buttons/home1a.gif')"
onmouseout="roll('sub_but1', 'http://www.kidsoft.org.uk/buttons/home1.gif')"

Any ideas or subtle pointers

many thanks

Rob B
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Script works in Mozilla but not IE6 (latest versions)?




These are usually identifier conflicts. Try a more explicit scope:

function roll(img_name, img_src)
{
document.images[img_name].src = img_src;
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Michael Winter
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Script works in Mozilla but not IE6 (latest versions)?


On 5 Dec 2004 18:43:44 -0800, mark <kidsoft@dsl.pipex.com> wrote:

[snip]
[color=blue]
> <SCRIPT LANGUAGE="JAVASCRIPT">[/color]

The language attribute has been deprecated for over six years. Use the
(required) type attribute instead:

<script type="text/javascript">
[color=blue]
> <!--[/color]

Hiding scripts like that is also an out-dated practice.
[color=blue]
> function roll(img_name, img_src)
> {
> document[img_name].src = img_src;[/color]

There is no reason for a named image to be a property of the document
object. Images have their own collection, images, so it's best to use that:

document.images[img_name].src = img_src;

[snip]
[color=blue]
> onmouseover="roll('sub_but1',
> 'http://www.kidsoft.org.uk/buttons/home1a.gif')"
> onmouseout="roll('sub_but1',
> 'http://www.kidsoft.org.uk/buttons/home1.gif')"[/color]

That's a very cumbersome way to perform rollovers.
[color=blue]
> Any ideas or subtle pointers[/color]

Have a look at <URL:http://www.mlwinter.pwp.blueyonder.co.uk/image-swap/>.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Closed Thread


Similar JavaScript / Ajax / DHTML bytes