Forum Moderators: open

Message Too Old, No Replies

can't change cell background via onclick function

         

parjinder

10:51 am on Oct 11, 2001 (gmt 0)



i need to to a similar thing but can't...can anyone help?

in a table cell, with id='finish2td', onclicking calls a function that is meant to change its background to an image called 'qestion.jpg' using this code in that function:

self.finish2td.style.background='url(qestion2.jpg)';

but doesn't.

can any1 help plz?

tedster

2:32 pm on Oct 11, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the forums, parjinder. Debugging JavaScript can be a pain in the nether regions, can't it?

My first suggestion is to open the page in Netscape 4.x, try the click, and then type "javascript:" in the location bar. The error messages Netscape gives for buggy javascript are not very precise, but they do pinpoint the exact spot in the code where troubles start.

If you're still having troubles after that, send me the URL in a "sticky mail" (see the menu at the top of the screen).

claw

10:26 pm on Oct 23, 2001 (gmt 0)



look at this source. for me it works
[tommypage.f2s.com...]

look at the bottom of the page and in the javascript section

IanKelley

8:33 am on Oct 24, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That page (TommyPage) doesn't appear to have any mouseover functions whatsoever :-)

If it does they're not working in IE 5.5. I didn't check the source.

About the original question... There are a couple things you can do.

First off, have you tried just:
self.style.backgound or
finish2td.style.background
istead of both? That's probably your problem.

You could also do it inline which would make sense because it doesn't look like you're calling it more than once:
onmouseover="style.background='url(qestion2.jpg)'; "

joshie76

12:45 pm on Oct 24, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Similarly to Tedsters NN4.X 'javascript:' trick. In IE you will notice that a little Alert document will appear in the left-hand corner of the status bar of the browser when there is some problem JavaScript.

Double click on that icon and a window will appear pinpointing the beginning of the problem and a brief description.

----

Given the nature of what you're doing I guess your aiming at fairly solid browsers (IE5+ and NN6), in which case the getElementById() method is invaluable.

<script>
document.getElementById('finish2td').background = "imageURL"
</script>

NB. Note that there is no style property in the object.

This works in IE5.5 but not NN6 - Not too sure why. Try the className property that we discussed in this forum [webmasterworld.com].

joshie76

12:59 pm on Oct 24, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry - missed this bit.

Where you use the self part of the object I assume you are referring to the object the call belongs to, i.e.

<table onclick="self.background='image.jpg'">

I may be wrong but I've never seen 'self' used in this way and the correct handler should be 'this'.

<table onclick="this.background='image.jpg'">

The only time i've seen 'self' used is in relation to windows (eg. window.self.location = 'test.htm').