PDA

View Full Version : Undefined Variables


Shadojack
08-07-2003, 12:45 AM
I've only recently started coding in Javascript in order to make my webpage more interactive and hopefully use it to find a better job.

Anyway I keep getting a "imageone Undefined" message.

In the scripting I have this


<script language=javasrcipt text="text/javascript">

if (document.images) {
imageone = new Image;
imagetwo = new Image;

imageone.src="bat1.gif";
imagetwo.src="bat2.gif";
}
</script>

When someone passes over a link the picture is supposed to change and then change back on a mouseout.

Any ideas?

whammy
08-07-2003, 12:55 AM
Yes:

imageone = new Image;
imagetwo = new Image;

should be:

imageone = new Image();
imagetwo = new Image();

since you're instantiating a new instance of the built-in Image() object in javascript, you need the parentheses there.

cheesebag
08-07-2003, 02:25 AM
Because it's a host constructor, the parentheses are optional. Is this a typo?

<script language=javasrcipt text="text/javascript">

Otherwise: let's see the rest of it.

whammy
08-07-2003, 02:27 AM
That should be set in stone... I hate optional exceptions like that. Either make me use parentheses, or don't! :)

But good call on the typo!

P.S. It should only be:

<script type="text/javascript">

that is if you care about the WC3, and recommendations...

cheesebag
08-07-2003, 02:34 AM
Yikes! I think they call that 'tunnel vision'. Missed that (interesting MIME type) completely. Nice call yourself, whammy. :D

whammy
08-07-2003, 02:51 AM
Really all that matters at the moment is if it works.

I really do aspire to the most up-to-date coding, but until they get all the bugs worked out, and until browser makers decide to "conform" (and compliant code works in all browsers!), you just have to use what works. :)

Shadojack
08-07-2003, 03:44 PM
Thanks cheesebag and whammy. That was the problem. Here I was concentrating on the code. Duh for me.