Solved: Re: [thelist] javascript image replace broken in gecko

danielEthan daniel at ionize.net
Fri Mar 7 13:27:01 CST 2003


> Daniel, the first thing I would do is read .jeff's excellent article
> "Links & JavaScript Living Together in Harmony":
>

Many times I have read this. My goal with this functionality was if you
don't have Javascript on, no biggie. I thought about changing the link
to a page saying you don't have javascript down the line, or just
writing the link with javascript. For now, returning false was fast.

> Secondly, you should first fix the errors in your JS that are already
> appearing. I am seeing at least an 'object expected' as well as
> 'return statement outside of function' in various places. (note: NS
> is great for JS errors, type "javascript:" in the address bar after
> you attempt something to see whats going on, it will give you great
> error reporting).
>

I think these are fixed by the solution. I wasn't creating a new image
before trying to swap it out. I guess you must create an image object
and then assign it to an image on the page.

> I also find that if I strip out everything but the actual widget I am
> working on in a separate page, it is much easier to work on. I would
> put one menu on a single page with nothing else (no status message,
> no nothing) and after reading that article, see what you come up with
> and post back here.
>

Thanks for the advice. That's good info.

> Also, display should always have a value, either "block", "inline" or
> "none", but not "".
>

Well, I would think so too. Here's the rub: On the first call, the
display value is blank. Second, there are four choices, list-item being
the fourth, and necessary here, because if I set it to block, I loose
the properties of list-items (namely the bullets). I'm sure I could
encompass them in a div, but then I'm kludging the code (not that I
have much room to talk about there-- tables spouting out everywhere) I
found that technique in Danny G's Dynamic HTML reference. It seems to
make sense, since there is no display property on load.

Tweaking Stef's first bit of code has brought about a solution. (Thanks
Stef.) It goes inline with what Tom was saying with the Object errors.
I'm now calling the newImage function (which creates an image and sets
its source from the argument). All is working in the browsers I've
tested so far. I'm sure that when I widen the scope, it'll stop
working. Pessimists are usually pleasantly surprised, optimists often
disappointed :o) What concerns me most is the n/a next to Netscape in
the DHTML ref (I have the first edition).

The working code is up at http://www.ionize.net/temp.html (since this
email is long enough already)

Regards,
Daniel




More information about the thelist mailing list