By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

Help with Image swap onmouseover event

P: n/a
Hi,

My onmousevent fails to switch the large photo with one of the smaller
images.

To be frank, I'm extremely new to Javascript programming and as such,
am trying to learn from other sites out there for sample code.

I can't see to determine the error.
>From my Frontpage editor, I receive the errors when I mouse over the
first image. (all images have the same problem.)

alt_0 is undefined
alt_1 is undefined (if i select the first image)

I've posted a sample page on my website to see if anyone can help

http://www.pctpoker.com/mens-poker-t...tail-test.html

If anyone can point me in the right direction, that would be great.

Thanks,
Steve.

Mar 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
st***********@gmail.com said the following on 3/10/2007 10:55 PM:
Hi,

My onmousevent fails to switch the large photo with one of the smaller
images.
It is because you have a syntax error in your script block.
To be frank, I'm extremely new to Javascript programming and as such,
am trying to learn from other sites out there for sample code.
Most sites on the web, that attempt to teach Javascript, are junk. If
you got your eval code in that page from such a site, it proves my point.

Yours:
function preload(imgObj,imgSrc) {
if (document.images) {
eval(imgObj + ' = new Image()')
eval(imgObj + '.src = "' + imgSrc + '"')
}
}

Re-written:
function preload(imgObj,imgSrc){
if (document.images){
window[imgObj] = new Image();
window[imgObj].src = imgSrc;
}
}
I can't see to determine the error.
Open your page in Firefox, it points straight at the error in the Error
Console.
>>From my Frontpage editor, I receive the errors when I mouse over the
first image. (all images have the same problem.)
If FP produced that code, it makes me glad I don't use it.
alt_0 is undefined
alt_1 is undefined (if i select the first image)
Look in the script section that has those definitions. After the
clearColor function (which is a bad function of it's own) on the very
next line (you will have to scroll over to see it) there is an errant }
in the code.

Yours:
function clearColor(){
document.all.colorDisplayName.style.display= "none";
}
Re-written:
function clearColor(){
document.getElementById('colorDisplayName').style. display = "none";
}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '07 #2

P: n/a
On Mar 11, 12:43 am, Randy Webb <HikksNotAtH...@aol.comwrote:
steve.peti...@gmail.com said the following on 3/10/2007 10:55 PM:
Hi,
My onmousevent fails to switch the large photo with one of the smaller
images.

It is because you have a syntax error in your script block.
To be frank, I'm extremely new to Javascript programming and as such,
am trying to learn from other sites out there for sample code.

Most sites on the web, that attempt to teach Javascript, are junk. If
you got your eval code in that page from such a site, it proves my point.

Yours:
function preload(imgObj,imgSrc) {
if (document.images) {
eval(imgObj + ' = new Image()')
eval(imgObj + '.src = "' + imgSrc + '"')
}

}

Re-written:
function preload(imgObj,imgSrc){
if (document.images){
window[imgObj] = new Image();
window[imgObj].src = imgSrc;

}
}
I can't see to determine the error.

Open your page in Firefox, it points straight at the error in the Error
Console.
>From my Frontpage editor, I receive the errors when I mouse over the
first image. (all images have the same problem.)

If FP produced that code, it makes me glad I don't use it.
alt_0 is undefined
alt_1 is undefined (if i select the first image)

Look in the script section that has those definitions. After the
clearColor function (which is a bad function of it's own) on the very
next line (you will have to scroll over to see it) there is an errant }
in the code.

Yours:
function clearColor(){
document.all.colorDisplayName.style.display= "none";}

Re-written:
function clearColor(){
document.getElementById('colorDisplayName').style. display = "none";

}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Thanks for the suggestions, they did resolve my initial problem and
the swap image works for both IE and Firefox, albeit with some errors,
but its a start!

I still receive the following error:
Error: document.getElementById("colorDisplayName") has no properties
Source File: http://www.pctpoker.com/mens-poker-t...tail-test.html
Line: 183

Based on what I could find in the maillist archives, it appears to be
a likely a syntax or html coding error.
Before I rip the entire pages apart to bare bones, can anyone see
something obvious I'm missing?

Thanks,Steve.

Mar 11 '07 #3

P: n/a
st***********@gmail.com said the following on 3/11/2007 2:04 PM:
On Mar 11, 12:43 am, Randy Webb <HikksNotAtH...@aol.comwrote:
>steve.peti...@gmail.com said the following on 3/10/2007 10:55 PM:
>>Hi,
My onmousevent fails to switch the large photo with one of the smaller
images.
It is because you have a syntax error in your script block.
>>To be frank, I'm extremely new to Javascript programming and as such,
am trying to learn from other sites out there for sample code.
Most sites on the web, that attempt to teach Javascript, are junk. If
you got your eval code in that page from such a site, it proves my point.

Yours:
function preload(imgObj,imgSrc) {
if (document.images) {
eval(imgObj + ' = new Image()')
eval(imgObj + '.src = "' + imgSrc + '"')
}

}

Re-written:
function preload(imgObj,imgSrc){
if (document.images){
window[imgObj] = new Image();
window[imgObj].src = imgSrc;

}
}
>>I can't see to determine the error.
Open your page in Firefox, it points straight at the error in the Error
Console.
>>From my Frontpage editor, I receive the errors when I mouse over the
first image. (all images have the same problem.)
If FP produced that code, it makes me glad I don't use it.
>>alt_0 is undefined
alt_1 is undefined (if i select the first image)
Look in the script section that has those definitions. After the
clearColor function (which is a bad function of it's own) on the very
next line (you will have to scroll over to see it) there is an errant }
in the code.

Yours:
function clearColor(){
document.all.colorDisplayName.style.display= "none";}

Re-written:
function clearColor(){
document.getElementById('colorDisplayName').style .display = "none";

}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Thanks for the suggestions, they did resolve my initial problem and
the swap image works for both IE and Firefox, albeit with some errors,
but its a start!

I still receive the following error:
Error: document.getElementById("colorDisplayName") has no properties
Source File: http://www.pctpoker.com/mens-poker-t...tail-test.html
Line: 183
In all 798 lines of code in that page, there are only 4 references to
colorDisplayName:

function swapSwatch has two references:
document.all.colorDisplayName.style.display= "inline"
document.all.colorDisplayName.innerHTML= "SHOWN HERE\: "
function swapSelect has one:
document.all.colorDisplayName.innerHTML=

function clearColor also has one:
document.getElementById('colorDisplayName').style. display = "none";

Yet nowhere in the document is there anything with an ID or NAME of
colorDisplayName nor is it defined anywhere as a variable. It appears,
from the code above, that colorDisplayName was intended to be a DIV or
SPAN element for updating/debugging that got removed.

Based on what I could find in the maillist archives, it appears to be
a likely a syntax or html coding error.
Looks like an HTML error where you changed an ID somewhere or removed it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.