Can someone please take a look at this script and maybe tell me whats going wrong?
I THINK that its not in the functions because it loads without error but as soon as io place the mouse over it, i get an error notice in the browser status bar.
heres the code:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code /font><HR><pre>
<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
newsOn = new Image(36, 120);
newsOn.src = "images/news_on.gif";
newsOff = new Image(36, 120);
newsOff.src = "images/news_off.gif";
// End -->
</script>
</head>
<script language="javascript">
<!--
function imageOn(imgName) {
if (browserOK == "yes") {
imgOn = eval(imgName + "On.src");
document[imgName].src = imgOn;
}
}
function imageOff(imgName) {
if (browserOK == "yes") {
imgOff = eval(imgName + "Off.src");
document[imgName].src = imgOff;
}
}
-->
</script>
<body>
<a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOn('news')">
<img name="news" src="images/news_off.gif" border="0">
</a>
</body>
</html>
[/code]
please help, ive been kicking this horse for hours... This is my first javascript installation and its not treating me kindly =(
but i want a mousover script that works with as many browsers as possible
Thank you so much
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote /font><HR>Originally posted by jizbot:
<a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOn('news')">
<img name="news" src="images/news_off.gif" border="0">
</a>
[/B]<HR></BLOCKQUOTE>
onMouseOut = "imageOff('news')"
should do it
and whats BrowserOK? Does the error you are getting look like this: 'BrowserOK' is undefined??
Your Lord and Master, Foamy
BrowserOK is most likely a flag that can be checked to see if the procedure will work.
For Example:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code /font><HR><pre>
BrowserOK ="No"
if document.images {BrowserOk = "Yes"}
[/code]
This will tell the script if the browser is capable of scripting images.
------------------
Wayne Luke - Sitepoint Forums Administrator
Digital Magician Magazine - MetaQuark Creations (Coming Soon)
wayne@sitepoint.com
yes browserOk is a variable that hold "yes" or "no" after a test is run to make sure the browser is either IE 3 or above or NE 4 or above i believe
sorry i didnt realize i didnt post that too =(
ok heres the full code:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code /font><HR><pre>
<html>
<head>
<title>Untitled</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if ((browserName == "Netscape" && browserVer >= 3) | | (browserName == "Microsoft Internet Explorer" && browserVer >=4)) {
browserOK = "yes";
else
browserOK = "no";
}
if (browserOK == "yes")
newsOn = new Image(36, 120);
newsOn.src = "images/news_on.gif";
newsOff = new Image(36, 120);
newsOff.src = "images/news_off.gif";
function imageOn(imgName) {
if (browserOK == "yes") {
imgOn = eval(imgName + "On.src");
document[imgName].src = imgOn;
}
}
function imageOff(imgName) {
if (browserOK == "yes") {
imgOff = eval(imgName + "Off.src");
document[imgName].src = imgOff;
}
}
-->
</script>
<body>
<a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOff('news')">
<img name="news" src="images/news_off.gif" border="0">
</a>
</body>
</html>
[/code]
Shouldn't this one section of code look like this??
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code /font><HR><pre>
if ((browserName == "Netscape" && browserVer >= 3) | | (browserName == "Microsoft Internet Explorer" && browserVer >=4)) {
browserOK = "yes";
}
else
{
browserOK = "no";
}
if (browserOK == "yes") {
newsOn = new Image(36, 120);
newsOn.src = "images/news_on.gif";
newsOff = new Image(36, 120);
newsOff.src = "images/news_off.gif";
}
[/code]
I added a closing bracket around the if browserOK == "yes" statement and added some more brackets to the code before it...
I don't know a whole lot about javascript, but it would make sense for it to be coded like this.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks