Forum Moderators: open

Message Too Old, No Replies

Javascript and Firefox

Litle problem but I can find....

         

forie

10:25 am on Oct 29, 2007 (gmt 0)

10+ Year Member



Hallo all,

I use some simple code for a menu script to make text hi-lighted and low-lighted IE5,6 and 7 has NO problem, but FF...... Keeps the text invisible.

This is the Java script I use:
<SCRIPT Language="javascript">

var browser_string1 = "";
var browser_string2 = "";

if (document.layers) {// navigator

browser_string1 = "layers.";
browser_string2 = "";

} else if (document.all) {// ie

browser_string1 = "all.";
browser_string2 = ".style";

} else {// FF;
browser_string1 = "getElementById.";
browser_string2 = ".style";

}

function highlight(tekstid) {
if (document.all) {
eval("document." + browser_string1 + tekstid + browser_string2 + ".color = '000000'");
}
}

function lowlight(tekstid) {
if (document.all) {
eval("document." + browser_string1 + tekstid + browser_string2 + ".color = 'cccccc'");
}
}

</SCRIPT>

And the html:

<TR>
<TD width=1>
</TD>
<TD BGCOLOR="F2F2F2" width=8 >
</TD>
<TD BGCOLOR="F2F2F2" width=153 align=right>
<FONT SIZE=3 FACE="VERDANA">
<B>
<A HREF="home.php" TARGET="home"
OnMouseOver="highlight('tekst1')"
OnMouseOut="lowlight('tekst1')">Home</A></B>
</font>
</TD>
<TD BGCOLOR="F2F2F2" width=8>
</TD>
</TR>

<TR>
<TD width=1>
</TD>
<TD BGCOLOR="F2F2F2" width=8 >
&nbsp;
</TD>
<TD VALIGN=TOP BGCOLOR="F2F2F2" width=153 align=right>
<FONT SIZE=2 FACE="VERDANA" COLOR="F2F2F2">
<DIV ID="tekst1">
Home
<BR>
</DIV>
</font>
</TD>
<TD BGCOLOR="F2F2F2" width=8>
</TD>
</TR>
<TR>
<TD width=1>
</TD>
<TD width=8 height=5>
</TD>
</TR>
<TR>
<TD width=1>
</TD>
<TD BGCOLOR="F2F2F2" width=8 >
</TD>
<TD BGCOLOR="F2F2F2" width=153 align=right>
<FONT SIZE=3 FACE="VERDANA">
<B>
<A HREF="home.php" TARGET="home"
OnMouseOver="highlight('tekst2')"
OnMouseOut="lowlight('tekst2')">Onze aanpak</A></B>
</font>
</TD>
<TD BGCOLOR="F2F2F2" width=8>
</TD>
</TR>

<TR>
<TD width=1>
</TD>
<TD BGCOLOR="F2F2F2" width=8 >
&nbsp;
</TD>
<TD VALIGN=TOP BGCOLOR="F2F2F2" width=153 align=right>
<FONT SIZE=2 FACE="VERDANA" COLOR="F2F2F2">
<DIV ID="tekst2">
Het traject
<BR>
</DIV>
</font>
</TD>
<TD BGCOLOR="F2F2F2" width=8>
</TD>
</TR>
etc etc

Please

penders

2:12 pm on Oct 29, 2007 (gmt 0)

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



Hi forie, your code is a bit out-of-date and consequently can be greatly simplified. Just looking at the JavaScript (since this is the JS forum)... all modern browsers (including IE5+) support getElementById(). You do not need to reference .layers (NN4?) or .all (IE4). But getElementById() is a function and needs to be called as such.

Keeping it simple, you can replace your entire SCRIPT section (and your 2 functions) with:

<script type="text/javascript"> 
function highlight(tekstid) {
document.getElementById(tekstid).style.color = '#000';
}
function lowlight(tekstid) {
document.getElementById(tekstid).style.color = '#ccc';
}
</script>

Hope that helps, if you need any further explanation just say.
...welcome to WebmasterWorld! :)

forie

3:28 pm on Oct 29, 2007 (gmt 0)

10+ Year Member



He Penders! Thank you very much!

This is the solution!
1000 time thanks!