Click to See Complete Forum and Search --> : Declare id for TD and Table in NS not done???
snoopy0877
09-23-2003, 10:56 PM
I have trouble in Netscape with this code:
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="ChangeBgTable">
<tr>
<td id="ChangeText">My text</td>
</tr>
</table>
I create 2 id in this table id="ChangeBgTable" and id="ChangeText"
Below I wrote:
<a href="#"><img src="services_mh1.jpg" onMouseOver="window.document.all('ChangeBgTable').style.backgroundImage=ImageArr[1]; window.document.all('ChangeText').innerText = TextArr[1];"></a>
<a href='#'><img src="services_mh2.jpg" onMouseOver="window.document.all('ChangeBgTable').style.backgroundImage=ImageArr[2]; window.document.all('ChangeText').innerText = TextArr[2];"></a>
I have the script:
ImageArr[1]='url(services_bg1.jpg)';
ImageArr[2]='url(services_bg2.jpg)';
TextArr[1]='text 1';
TextArr[2]="text 2";
This script done correct in IE but in Netscape its not done. In javascript screen write: window.document.all is not a function
These id is not declare right for javascript???
can you show me how to change this for NS and IE both work right, thanks
document.all is IE only. Try the DOM method of document.getElementById("someid") instead.
snoopy0877
09-24-2003, 02:48 AM
<a href="#"><img src="services_mh1.jpg" onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage=ImageArr[1]; document.getElementById('ChangeText').innerText = TextArr[1];"></a>
<a href='#'><img src="services_mh2.jpg" onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage=ImageArr[2]; document.getElementById('ChangeText').innerText = TextArr[2];"></a>
I had change window.documnet.all => document.getElementById but it still not done. Have any code to make the same?
gil davis
09-24-2003, 06:31 AM
You did not specify what version of NS. It would be difficult to make your code work in NS 4. It does not support mouseover on the image tag, getElementById, or innerText.
NS 6 and 7 also do not support innerText. They do support innerHTML, though.
snoopy0877
09-24-2003, 09:06 PM
I use NS6 for test this code. Thanks gil davis and pyro, I had change it to:
<a href="#" onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage=ImageArr[1]; document.getElementById('ChangeText').innerHTML = TextArr[1];" onMouseOut="document.getElementById('ChangeBgTable').style.backgroundImage='';">aaa</a>
<a href='#' onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage=ImageArr[2]; document.getElementById('ChangeText').innerHTML = TextArr[2];" onMouseOut="document.getElementById('ChangeBgTable').style.backgroundImage='';">bbb</a>
And I had change the TEXT when MouseOver the link, BUT the imagebg still not change, its change the imgbg once when the first mouseover the link but in the second and later its not done. Have a alternative code for this effect?
gil davis
09-24-2003, 09:20 PM
To change a backgroundImage in NS 6, you need to specify a URL in the form:
document.getElementById('ChangeBgTable').style.backgroundImage = "url(" + ImageArr[2] + ")";
snoopy0877
09-24-2003, 09:40 PM
Originally posted by gil davis
To change a backgroundImage in NS 6, you need to specify a URL in the form:
document.getElementById('ChangeBgTable').style.backgroundImage = "url(" + ImageArr[2] + ")";
I declared ImageArr[1]='ulr(services_bg1.jpg)'; ImageArr[2]='ulr(services_bg2.jpg)';
And I tried to change:
<a href="#" onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage='url('+ImageArr[1]+')'; document.getElementById('ChangeText').innerHTML = TextArr[1];">aaa</a>
<a href='#' onMouseOver="document.getElementById('ChangeBgTable').style.backgroundImage='url('+ImageArr[2]+')'; document.getElementById('ChangeText').innerHTML = TextArr[2];">bbb</a>
BUT it still not done correctly. its change the imgbg once when the first mouseover the link but in the second and later its not done
gil davis
09-25-2003, 02:01 PM
In my suggestion, I did not mean for you to change your array.
Have you used the Javascript console under the Tools menu to look for errors? It could be that you have errors that are not related to the issue at hand.
It would help if you can post a link to your page.
snoopy0877
09-25-2003, 09:15 PM
I don't have a site to post. It's my exercise. I had used the Javascript console. But It's not notice anything