473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

document.images[imgName] has no properties

I get the following error when I try to rollover my button:

document.images[imgName] has no properties Line: 22

Am I doing this correctly? Suggestions? This is using Netscape 7.2
on Fedora core 4.

Here's my simple html file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<script type="text/javascript">
<!-- HIDE

if (document.images)
{
document.images["order1"] = new Image(135,40);
document.images["order1"].src = "images/ordernow1.jpg";;
document.images["order2"] = new Image(135,40);
document.images["order2"].src = "images/ordernow2.jpg";;
}

function rollover(imgName,src)
{
if (document.images)
{
document.images[imgName].src = src;
return false;
}
return true;
}

// DONE hiding -->
</script>

</head>

<body>

<a href="http://www.mysite.com/order.html"
onMouseover="return rollover('order2','images/ordernow2.jpg');"
onMouseout="return rollover('order1','images/ordernow1.jpg');">
<img src="images/ordernow1.jpg">
</a>

</body>
</html>

Nov 23 '05 #1
9 3926
VK

Jeff wrote:
I get the following error when I try to rollover my button:

document.images[imgName] has no properties Line: 22


Change:
function rollover(imgName,src)
{
if (document.images)
{
document.images[imgName].src = src;
return false;
}
return true;
}

to

function rollover(imgName,neverUseNativeNameAsVarName)
{
if (document.images)
{
document.images[imgName].src = neverUseNativeNameAsVarName;
return false;
}
return true;
}

;-)

Nov 23 '05 #2
Ok, that was a dumb mistake on my part :) However,
changing the 'src' variable to anything else still doesnt
work. I still get the same error.

Just a note on my orig code, IE doesnt complain at all.
Im using IE 6.0. Then again it doesnt rollover either, but
no errors.

Thanks for the first part, try again? :)

Nov 23 '05 #3
On 21/11/2005 19:17, Jeff wrote:

[snip]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Unless you /need/ a Transitional feature, use a Strict document type
declaration.

[snip]
<script type="text/javascript">
<!-- HIDE
Hide from what? Browsers that are old enough not to recognise a SCRIPT
element (even if they don't support client-side scripts) aren't used on
the Web, not least because they're all but useless now.
if (document.images)
{
document.images["order1"] = new Image(135,40);
The images collection should be used to /retrieve/ images already in the
document. Create a new object to retain image objects for preloading
purposes:

var preload = {};

/* Check for support of the Image constructor */
if(('object' == typeof Image) || ('function' == typeof Image)) {
/* Preload */
preload.order1 = new Image(135, 40);
preload.order1.src = 'images/ordernow1.jpg';

/* ... */
}

[snip]
<a href="http://www.mysite.com/order.html"
onMouseover="return rollover('order2','images/ordernow2.jpg');"
onMouseout="return rollover('order1','images/ordernow1.jpg');">
Your rollover function will attempt to look for IMG elements with a name
or id attribute value of 'order1' and 'order2' (depending on the event),
but no such element exists. This is why your code fails.
<img src="images/ordernow1.jpg">


This element should have an alt attribute (required, even if an empty
string), and must be identified so that the script can reference it.
Change the strings in the event listeners above to reflect this name:

<a href="..."
onmouseover="rollover('order', 'images/ordernow2.jpg');"
onmouseout="rollover('order', 'images/ordernow1.jpg');">
<img id="order" name="order"
alt="..."
src="images/ordernow1.jpg">
</a>

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Nov 23 '05 #4
On 21/11/2005 21:11, Jeff wrote:
Ok, that was a dumb mistake on my part :)


No, it wasn't. You can use the identifier, src, if you want.

[snip]

Mike
Please quote when you're replying to a post. You can do this with Google
Groups by opening the options panel (show options) at the top of the
post you want to reply to and select 'Reply' from there.

Trim away text that is irrelevant to your reply (preferably indicating
that you've done so), and interleave your comments.

See <http://www.jibbering.com/faq/faq_notes/clj_posts.html>,
particularly the section on 'Interleaved Posting...'.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Nov 23 '05 #5
Jeff said the following on 11/21/2005 2:17 PM:
I get the following error when I try to rollover my button:

document.images[imgName] has no properties Line: 22

Am I doing this correctly? Suggestions? This is using Netscape 7.2
on Fedora core 4.

Here's my simple html file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<script type="text/javascript">
<!-- HIDE

if (document.images)
{
document.images["order1"] = new Image(135,40);
document.images["order1"].src = "images/ordernow1.jpg";;
document.images["order2"] = new Image(135,40);
document.images["order2"].src = "images/ordernow2.jpg";;
}

function rollover(imgName,src)
{
if (document.images)
{
document.images[imgName].src = src;
return false;
}
return true;
}

// DONE hiding -->
</script>

</head>

<body>

<a href="http://www.mysite.com/order.html"
onMouseover="return rollover('order2','images/ordernow2.jpg');"
onMouseout="return rollover('order1','images/ordernow1.jpg');">
<img src="images/ordernow1.jpg">


Ignore VK and his ramblings, we are still trying to educate him. Give
your img tag a NAME attribute:

<img src="something.." name="myImage">

document.images['myImage'].src="....."

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #6
Thanks to all for teaching me some things I didnt know.
I did what Randy said and it worked just fine.

Thanks!

Nov 23 '05 #7
On 21/11/2005 21:32, Michael Winter wrote:

[snip]
Hide from what? Browsers that are old enough not to recognise a SCRIPT
element (even if they don't support client-side scripts) aren't used on
the Web, not least because they're all but useless now.


Hmm. That didn't come out quite right.

All browsers currently in use on the Web recognise SCRIPT elements, even
if they don't support client-side scripts. They won't render the
contents of the element. If there is some other reason to 'hide' a
script, the better solution would be to place it in an external file.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Nov 23 '05 #8
On 2005-11-21, Jeff <je**@rahul.net> wrote:
I get the following error when I try to rollover my button:
Here's my simple html file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" document.images["order1"] = new Image(135,40);>
this image doesn't appear to be part of your dcument.
where does the name "order1" come frem - what are you doing to ensure that
this new image keeps that name.

onMouseover="return rollover('order2','images/ordernow2.jpg');"
onMouseout="return rollover('order1','images/ordernow1.jpg');"> ^
|
|
for HTML 4.01 Transitional this should be lower case IIRC
<img src="images/ordernow1.jpg">


nope, that desn't match it....

--

Bye.
Jasen
Nov 23 '05 #9
Jasen Betts said the following on 11/22/2005 2:48 PM:
On 2005-11-21, Jeff <je**@rahul.net> wrote:
I get the following error when I try to rollover my button:
Here's my simple html file:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


document.images["order1"] = new Image(135,40);>

this image doesn't appear to be part of your dcument.
where does the name "order1" come frem - what are you doing to ensure that
this new image keeps that name.


And it doesn't matter. It is just a preloading routine.

onMouseover="return rollover('order2','images/ordernow2.jpg');"
onMouseout="return rollover('order1','images/ordernow1.jpg');">


^
|
|
for HTML 4.01 Transitional this should be lower case IIRC


No, it doesn't matter. Not in HTML4.01 anyway.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CJ | last post by:
Hi In my PHP script I'm able to update bookmarks without in hassles but document properties just don't work! I know in VB custom properties can be changed with the following: ...
3
by: StrongBad | last post by:
Does anyone know of a way to access the document properties of an office document using ASP? I need to be able to read things like the Title, Author, and Comments fields and pull that information...
1
by: Patrick Conway | last post by:
Hi! I'm building a Windows form that allows users to view a list of files (and their properties(metadata)) stored in a certain directory. All of the files in the directory are a result of a...
2
by: Mad Joe | last post by:
This piece of code is working in IE, but not in my Firefox. The last link should simulate onclick event on the upper image. Can you suggest me how to make it crossbrowser compatible, please? ...
0
by: Alan T | last post by:
I have modified custom properties of a Word document by code. And there are fields in this Word document link to the properties, however, after running the application and reopen the document, the...
4
by: Morgan | last post by:
Hello! I'm trying to find out if it's possible to access the properties of an document uploaded via the fileupload control? The end goal is to dynamically insert the number of pages in a document...
0
by: Support | last post by:
Hello: Apparently we can read and write to Document Properties using Dsofile.dll (seel http://support.microsoft.com/?id=224351) My question is: can this be extended to non-native Microsoft...
3
by: Maurizio | last post by:
I create an application with Access 2000 and I wish to read/write the properties of a specified word document. I use dsofile.dll my code is Function fGetDocProps(strInFile As String, strProp As...
0
by: hannahhhh1056 | last post by:
Hello! I´m trying to create a makro that finds the text in a wddocument formatted as "heading 1" and then puts it in the document properties. I know how to get the text into doc properties but i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.