473,396 Members | 1,775 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,396 software developers and data experts.

Determine if image source exists?

I have a list of dynamically generated Parts that can be used to add to an
Order. The list includes an image with the src set to
"WhateverThePartNumberIs.png" in a particular folder.

Not all part numbers have images so the alt text "No Image Available" is
displayed in those cases.

Can my JavaScript onclick code "know" when the image clicked on is actually
displaying an image and not the alt text? I open a window with a larger
version of the image in this event and would like to NOT do so when there is
no image.

TIA
Jun 1 '06 #1
6 6779
On 01/06/2006 14:09, Rick Brandt wrote:
I have a list of dynamically generated Parts that can be used to add
to an Order.
What generates these parts? The server?
The list includes an image with the src set to
"WhateverThePartNumberIs.png" in a particular folder.

Not all part numbers have images so the alt text "No Image Available"
is displayed in those cases.


Based on that description and the subject of your post, I'd have to
assume then that you generate markup such as,

<img alt="No Image Available"
src="image-that-does-exist.png">

which is inappropriate. The alternative text should be a replacement for
/that/ image, not some generic comment. In this case, it should be
something more like "Profile shot of [product name]." or, depending on
how the image is presented, an empty string.

If no image is available - to be determined whilst generating the
content - then the img element shouldn't be present at all, only the
text, "No image available."

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jun 1 '06 #2
Rick Brandt wrote:
I have a list of dynamically generated Parts that can be used to add to an
Order. The list includes an image with the src set to
"WhateverThePartNumberIs.png" in a particular folder.

Not all part numbers have images so the alt text "No Image Available" is
displayed in those cases.

Can my JavaScript onclick code "know" when the image clicked on is
actually
displaying an image and not the alt text? I open a window with a larger
version of the image in this event and would like to NOT do so when there
is no image.

TIA


Hi,

Yes, it is possible.
You can add an eventhandler to your window that fires your own function if
any error occurs.
window.onerror = yourHandler;

or you can add the handler to an image, which is maybe more appropriate.
Read more here:
http://www.faqts.com/knowledge_base/view.phtml/aid/1799

But since you are probably working serverside already, why not do the
checking from your PHP/VB/Perl/whatever scripts on the server?
Sounds a lot easier to me and also gives a faster userexperience.
If you let JS do the checking and replacing, JS has to go to the server to
try to fetch an image, and if no succes, fetch another.
If possible, solve this serverside.

Regards,
Erwin Moller
Jun 1 '06 #3
Rick Brandt wrote:
Can my JavaScript onclick code "know" when the image clicked on is
actually displaying an image and not the alt text?


Sort of. Example:

<img src="/asdf.jpg" alt="Alt Text" onclick="alert('onclick')"
onerror="this.onclick=null">

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 1 '06 #4
Michael Winter wrote:
On 01/06/2006 14:09, Rick Brandt wrote:
I have a list of dynamically generated Parts that can be used to add
to an Order.


What generates these parts? The server?


I have an XML document that is a list of parts retrieved from a database
query. That xml is styled with an XSL sheet to produce a HTML table. It is
this table that produces the img element.

The database has no idea whether there is an image file for any particular
part number. We only know that if there is an image that it will be a png
file with the same name as the part number. So the src is always set to
that string value and when there is no image we see the alt text.

I would just like to NOT execute the code for displaying the larger image
when in fact there is no image to display.
The list includes an image with the src set to
"WhateverThePartNumberIs.png" in a particular folder.

Not all part numbers have images so the alt text "No Image Available"
is displayed in those cases.


Based on that description and the subject of your post, I'd have to
assume then that you generate markup such as,

<img alt="No Image Available"
src="image-that-does-exist.png">

which is inappropriate. The alternative text should be a replacement
for /that/ image, not some generic comment. In this case, it should be
something more like "Profile shot of [product name]." or, depending on
how the image is presented, an empty string.

If no image is available - to be determined whilst generating the
content - then the img element shouldn't be present at all, only the
text, "No image available."


When the content is generated we do not have the information about whether
the image exists.
Jun 1 '06 #5
Erwin Moller wrote:

Yes, it is possible.
You can add an eventhandler to your window that fires your own
function if any error occurs.
window.onerror = yourHandler;
I will look into this, thanks.
or you can add the handler to an image, which is maybe more
appropriate. Read more here:
http://www.faqts.com/knowledge_base/view.phtml/aid/1799

But since you are probably working serverside already, why not do the
checking from your PHP/VB/Perl/whatever scripts on the server?
Sounds a lot easier to me and also gives a faster userexperience.
If you let JS do the checking and replacing, JS has to go to the
server to try to fetch an image, and if no succes, fetch another.
If possible, solve this serverside.

Regards,
Erwin Moller


I'm a bit new to this so perhaps the question doesn't seem logical. My
thinking was that the HTML document seems to "know" when there is no image
because it is displaying the alt text in its place. I just thought there
was a way for my script to "see" the same thing the users can see and simply
do nothing unless a thumb image is being displayed.

This table is not being built server side. I am creating it by processing
an XML document via an XSL sheet on the client. The XML document does not
contain any information about whether there is an image file available for
the part. We only know that IF there is an image it will have the part
number as its name.
Jun 1 '06 #6
TC

Rick Brandt wrote:
I have an XML document that is a list of parts retrieved from a database
query. That xml is styled with an XSL sheet to produce a HTML table. It is
this table that produces the img element.

The database has no idea whether there is an image file for any particular
part number. We only know that if there is an image that it will be a png
file with the same name as the part number. So the src is always set to
that string value and when there is no image we see the alt text.

Is this right: the images are on the server, and you want the
javascript on the /client/ to behave differently, depending on whether
the relevant image is or is not on the /server/?

If so, I think you should try to do the check on the server - not the
client. Isn't there some way for your database code to check for the
images, and include that information in the XML? Perhaps each node
could have a new element 'hasImage', or somesuch. Then the XSL could
translate that into different HTML.

Or could a seperate process on the server take the current XML result,
check for the relevant images, then merge-in those results, before
returning the XML to the client?

Just some ideas, I'm no expert on this.

HTH,
TC (MVP MSAccess)
http://tc2.atspace.com

Jun 1 '06 #7

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

Similar topics

8
by: Phil Powell | last post by:
I borrowed this code from a source: for($a=0;$a<imagecolorstotal ($image_id);$a++) { $color = imageColorsForIndex($image_id,$i); $R=.299 * ($color)+ .587 * ($color)+ .114 * ($color);...
7
by: Kamus of Kadizhar | last post by:
Thanks to everyone on this list. I now have a functioning piece of python code!! :-)) Now I'm trying to clean it up. I have the same (or similar) lines repeated several times: ...
16
by: Donjuan | last post by:
Hi all I have trouble with tracking whether my image file is loaded. i use DHTML to change my image. HERE is the code: <img name="someimage" src="1.jpg"...
6
by: Michael | last post by:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a GIF. My code runs fine, and converts the image, but the quality is not anywhere close to as good. I know that GIF quality is...
7
by: Jean Christophe Avard | last post by:
Hi! I am designing an application wich comes with image file. These images are copyrighted and they have to be accessible only from within the application. At first, I tought I was going to store...
7
by: Stephen E. Weber | last post by:
I need to determine if a file exists using code. I tried using the system.io.file.exists function, that will appears to locate the file if I use the complete filespec, when I move the project to...
2
by: markcash | last post by:
I am trying to bind an ASP.NET image control to images stored locally on the hard drive of the web server. The images will be frequently changing so I am dynamically creating the filename. I am...
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
7
by: howardk | last post by:
I'm writing some code that loads a number of images, using the standard mechanism of assigning a src url to a newly constructed Image object, thus invoking the image-load operation. On a successful...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.