473,404 Members | 2,114 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,404 software developers and data experts.

Image creation problem

I have a subroutine that inserts image objects into
a page for me. It works fine except for one thing.
My mouseover settings don't appear to take. i.e. I
see nothing at all when I move the mouse cursor over
the image. If I replace the object creation code with
a plain document.write, it works. :

// this works as expected
document.write("<img src='marker12.gif' \
id='1' \
onmouseover='return overlib(\"First Image\");' \
onmouseout='return nd();'/>"
);
// this creates the image, but the mouseover does not work
imgObj = document.createElement("img");
imgObj.src = "marker12.gif";
imgObj.onmouseover="return overlib(\"Second Image\");";
imgObj.onmouseout="return nd();";
imgObj.id = 2;
document.body.appendChild(imgObj);

The behavior is the same in IE as it is in Mozilla.

I'm a newbie at this, Can anyone see what I'm doing wrong?

Thanks,
Jim Buzbee

--
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jb*****@nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain
Jul 20 '05 #1
5 1764
Following up to myself :

The code below works in Mozilla but not in
IE when I replace the "imgObj.onmouseover=" statment with :

imgObj.setAttribute("onmouseover", "return overlib(\"Second Image\");");

I do the same type of thing with the onmouseout statement.
Hints? Suggestions? Is there a better way to be doing this?

Jim
In article <10***************@irys.nyx.net>,
Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
I have a subroutine that inserts image objects into
a page for me. It works fine except for one thing.
My mouseover settings don't appear to take. i.e. I
see nothing at all when I move the mouse cursor over
the image. If I replace the object creation code with
a plain document.write, it works. :

// this works as expected
document.write("<img src='marker12.gif' \
id='1' \
onmouseover='return overlib(\"First Image\");' \
onmouseout='return nd();'/>"
);
// this creates the image, but the mouseover does not work
imgObj = document.createElement("img");
imgObj.src = "marker12.gif";
imgObj.onmouseover="return overlib(\"Second Image\");";
imgObj.onmouseout="return nd();";
imgObj.id = 2;
document.body.appendChild(imgObj);

The behavior is the same in IE as it is in Mozilla.

I'm a newbie at this, Can anyone see what I'm doing wrong?

Thanks,
Jim Buzbee

--
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jb*****@nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain

--
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jb*****@nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain
Jul 20 '05 #2
On 11 Feb 2004 10:23:59 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
Following up to myself :

The code below works in Mozilla but not in
IE when I replace the "imgObj.onmouseover=" statment with :

imgObj.setAttribute("onmouseover", "return overlib(\"Second Image\");");

I do the same type of thing with the onmouseout statement.

Hints? Suggestions? Is there a better way to be doing this?


[snip]

Try

imgObj.onmouseover = new Function('return overlib("Second Image");');

The problem with your original solution was that the event properties
expect a function reference, not a string. An alternative solution to the
above would be:

function callOverlib() {
return overlib('Second Image');
}
...
imgObj.onmouseover = callOverlib;

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
In article <op**************@news-text.blueyonder.co.uk>,
Michael Winter <M.******@blueyonder.co.invalid> wrote:
On 11 Feb 2004 10:23:59 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
....
The problem with your original solution was that the event properties
expect a function reference, not a string. An alternative solution to the
above would be:

function callOverlib() {
return overlib('Second Image');
}
...
imgObj.onmouseover = callOverlib;

Mike
Thanks much - That gets much closer. My original example oversimpilfied my problem.
What I -really- want to do is parameterize the "mouseOver" so that each
image has its own label. i.e. something like

....

description = "....
....
imgObj.setAttribute("description",description);
imgObj.onmouseover = callOverlib;

....

CallOverlib would extract the description attribute from the image and
call overlib.

Is there a way for the mouseover function (callOverlib in this case) to determine
which element "called" it? Just adding a parameter to callOverlib doesn't do the
trick.

I feel like I'm learning this language by trial, error, and google...

Jim



--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

--
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jb*****@nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain
Jul 20 '05 #4
On 11 Feb 2004 11:44:35 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
In article <op**************@news-text.blueyonder.co.uk>,
Michael Winter <M.******@blueyonder.co.invalid> wrote:
On 11 Feb 2004 10:23:59 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
...
The problem with your original solution was that the event properties
expect a function reference, not a string. An alternative solution to
the
above would be:

function callOverlib() {
return overlib('Second Image');
}
...
imgObj.onmouseover = callOverlib;

Mike


Thanks much - That gets much closer. My original example oversimpilfied
my problem.
What I -really- want to do is parameterize the "mouseOver" so that each
image has its own label. i.e. something like


Images do have a description attribute: alt. I must assume that it's
insufficient for some reason.

I will point out that the alt attribute is actually required.
description = "....
...
imgObj.setAttribute("description",description);
imgObj.onmouseover = callOverlib;

CallOverlib would extract the description attribute from the image and
call overlib.
What does overlib() expect? A string, an object reference?
Is there a way for the mouseover function (callOverlib in this case) to
determine which element "called" it? Just adding a parameter to
callOverlib doesn't do the trick.


The operator, this, refers to the current object. When used in a method,
it usually refers to the calling object. In the case of intrinsic events,
this refers to the element that the event is attached to. For example:

<img src="someImage.jpg" alt="Some random image"
onclick="alert(this.alt)">

Clicking on that image will display an alert box with the text, "Some
random image".

To pass the value of the description attribute as a parameter of
overlib(), you would do:

imgObj.onmouseover = new Function('return
overlib(this.getAttribute("description"))');

If you do use the alt attribute, the argument would be changed to
"this.alt". I don't know if "this.description" would be acceptable as it's
not a standard attribute.

If the mouseover event contents will always be the same, you can create a
function as I showed previously and assign it to the handlers:

function callOverlib() {
return overlib(this.getAttribute('description')); // or this.alt
}
...
imgObj.onmouseover = callOverlib;

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
In article <op**************@news-text.blueyonder.co.uk>,
Michael Winter <M.******@blueyonder.co.invalid> wrote:
On 11 Feb 2004 11:44:35 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
In article <op**************@news-text.blueyonder.co.uk>,
Michael Winter <M.******@blueyonder.co.invalid> wrote:
On 11 Feb 2004 10:23:59 -0700, Jim Buzbee <jb*****@nyx10.nyx.net> wrote:
....
Thanks much - That gets much closer. My original example oversimpilfied
my problem.
What I -really- want to do is parameterize the "mouseOver" so that each
image has its own label. i.e. something like
Images do have a description attribute: alt. I must assume that it's
insufficient for some reason.


No, I think I'll change it to alt. I started using "description" because
that what it was called in XML field I was grabbing it from.


I will point out that the alt attribute is actually required.
description = "....
...
imgObj.setAttribute("description",description);
imgObj.onmouseover = callOverlib;

CallOverlib would extract the description attribute from the image and
call overlib.
What does overlib() expect? A string, an object reference?


A String.

Is there a way for the mouseover function (callOverlib in this case) to
determine which element "called" it? Just adding a parameter to
callOverlib doesn't do the trick.
The operator, this, refers to the current object. When used in a method,
it usually refers to the calling object. In the case of intrinsic events,
this refers to the element that the event is attached to. For example:

<img src="someImage.jpg" alt="Some random image"
onclick="alert(this.alt)">

Clicking on that image will display an alert box with the text, "Some
random image".


OK - Thanks - "this" did the trick.


To pass the value of the description attribute as a parameter of
overlib(), you would do:

imgObj.onmouseover = new Function('return
overlib(this.getAttribute("description"))');

If you do use the alt attribute, the argument would be changed to
"this.alt". I don't know if "this.description" would be acceptable as it's
not a standard attribute.

If the mouseover event contents will always be the same, you can create a
function as I showed previously and assign it to the handlers:

function callOverlib() {
return overlib(this.getAttribute('description')); // or this.alt
}
...
imgObj.onmouseover = callOverlib;

Hope that helps,
Mike

Yes, it did. Very much so. Thanks for sharing the knowledge!

Jim

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

--
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jb*****@nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain
Jul 20 '05 #6

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

Similar topics

7
by: Nathan Sokalski | last post by:
I have been trying to find a way to prevent the images on my site from being cached on the user's machine. I want to avoid this because the images used in an Image control often change, yet have...
5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
4
by: Dean Card | last post by:
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the...
8
by: Alexander Fischer | last post by:
Hello, I am writing a gallery script and use imagecreatefromjpeg and fpassthru to output images without any change to them (i.e., no thumbnail creation etc. - just deliver the image via the php...
4
by: Greg | last post by:
I've searched everywhere for a solution Microsoft .NET Framework V 2.0.50727 AutoEventWireup="false" image2.aspx resize an image on the fly but Page_Load is triggered twice: Any suggestion?...
7
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g....
7
by: dino d. | last post by:
Hi- I want to create a dynamic image with areas so that when the user clicks different areas, the user jumps to those pages. The problem is, I can't seem to figure out how to do this efficiently....
3
by: RK | last post by:
Is there an image handling guru out there than can help a newbie with understanding dynamic image creation? The question: I can create an image from within Javascript with MyPic = new Image()...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.