Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

javascript onclick/ondblclick not working properly for images

Featured Replies

Hi all

 

On our classic car club website we have a writeup each month of the last event. The text includes photos that can be enlarged by clicking on them. A double click then restores the original photo. This is done by this JS code:

 

<img src="/non_gallery_photos/feb2009run/eco_hotel_start1.jpg" width=300 height=180 hspace=10   vspace=15 align=right alt="Eco Hotel Start" onclick="src='/non_gallery_photos/feb2009run/eco_hotel_start1.jpg'; width=500; height=280; hspace=10;   vspace=15 "; ondblclick="src='/non_gallery_photos/feb2009run/eco_hotel_start.jpg1'; width=300; height=180; hspace=10;   vspace=15 " />

 

However, each month, one out of three or four photos is "lazy" and won't return to the original state after being enlarged - a different one in a different location each month. It just shows the space and not the image - just the Alt tag. Anyone viewing the site has to hit F5 to refresh the page. When we write the story I usually cut and paste the above code from place to place and just change the align tags depending on the layout, so there shouldn't be any typos or whatever.

 

Please have a look if you would at this link of the offending page:

 

Sol Classic Car Club/Last Event where the first image is the problem.

 

Any help really appreciated.

 

Many thanks

 

RJ

I've not looked to much at it but I'd definately consider changing your inline code to a javascript function, something LIKE below:

 

<script type="text/javascript">

function resizeImage(image_id,new_image){

document.getElementById(image_id).src = new_image;

}
</script>

  • Author
I've not looked to much at it but I'd definately consider changing your inline code to a javascript function, something LIKE below:

 

<script type="text/javascript">

function resizeImage(image_id,new_image){

document.getElementById(image_id).src = new_image;

}
</script>

 

skidz - thanks for the reply. I'll certainly give this a go. I will have to find some info on the code itself, as I am a complete noob when it comes to js. The snippet I am using was a straight lift from code I found on the internet.

 

Thanks again.

On the double-click command on the first image, you are changing the source to eco_hotel_start.jpg1. Removing the 1 will solve your problem.

 

You may find it easier not to use your current script and use something like Lightbox to make a larger image appear when the user clicks on the image.

  • Author
On the double-click command on the first image, you are changing the source to eco_hotel_start.jpg1. Removing the 1 will solve your problem.

 

You may find it easier not to use your current script and use something like Lightbox to make a larger image appear when the user clicks on the image.

 

 

Brilliant - thanks for spotting the typo. I couldn't see the wood for the trees!

 

I'll look at Lightbox - muchas gracias for the help

 

RJ

 

EDIT: Can anyone help how to mark this up as SOLVED? Cheers

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.