473,396 Members | 1,833 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.

enlarge a thumbnail in the left cell of the table

4
Hi,
I have a table with 4 cells - 3 on the left containing 3 thumnails and 1 cell on the right to hold the enlarged image.
So when I click on the thumnail then the enlarged one should display on the right cell.
Below is my code and so far is not working - enlarged image displayed on the seperate page.
Can anyone help me with the scripts below?

thank you so much,
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.  <HEAD>
  4.   <TITLE> New Document </TITLE>
  5. <meta http-Equiv="Cache-Control" Content="no-cache">
  6. <meta http-Equiv="Pragma" Content="no-cache">
  7. <meta http-Equiv="Expires" Content="0">
  8.  
  9.  <script language="javascript">
  10.      function enlargeme()
  11.       {
  12.  
  13.         var bigpic=document.getElementById('img1');
  14.         bigpic.src="http://www.isdntek.com/tagbot/misc/dustyroses.jpg"; 
  15.         bigpic.width=200;
  16.         bigpic=height=200;
  17.         }
  18. </script>
  19.  
  20. <BODY>
  21. <TABLE BORDER=1 WIDTH=70%>
  22. <TR>
  23. <TD>
  24. <TABLE BORDER=1 WIDTH=100%>
  25. <TR>
  26. <TD><a href='http://www.isdntek.com/tagbot/misc/dustyroses.jpg' onclick='enlargeme()'>
  27. <img src='http://www.isdntek.com/tagbot/misc/dustyroses.jpg' width='72' height='72' hspace='2' border='0' style='border:0px ridge white' src='http://www.isdntek.com/tagbot/misc/dustyroses.jpg'></a>
  28.  
  29. </TD>
  30.  
  31. <TD>2nd img</TD>
  32. </TR>
  33.  
  34. <TR>
  35. <TD>3nd img</TD>
  36.  
  37. <TD>4th img</TD>
  38. </TR>
  39. </TABLE>
  40. </TD>
  41.  
  42. <TD>
  43. <TABLE>
  44. <TR>
  45. <td align='center' width='408' height='308'>
  46. <img src='http://www.isdntek.com/tagbot/misc/bambi.jpg' id='img1'  width='300' height='300' style='border:0px ridge white'>
  47. </td>
  48. </TR>
  49.  
  50. </TABLE>
  51. </TD>
  52. </TR>
  53. </TABLE>
  54.  
  55. </BODY>
  56.  
  57. </HTML>
Aug 11 '09 #1
7 2980
Dormilich
8,658 Expert Mod 8TB
to get started a little note. though it is not necessary for HTML it is recommended to write the tag and attribute names either upper- or lowercase (should not be mixed)

you get forwarded to the next page, because you use a valid link. so you have 3 options.
- omit the href
- suppress the href
- omit the link (my recommendation)

the next thing to do would be a way to store somewhere the information you need for the big picture, so you can use the same function for every thumbnail.

at last you only need to associate the event with the image.

ex.
Expand|Select|Wrap|Line Numbers
  1. // standard compliant (not IE)
  2. // the actual code also depends on how enlargeme() works
  3.  
  4. // this triggers the function enlargeme() whenever you click on the element
  5. // (img) with the ID "thumb1"
  6. document.getElementById("thumb1").addEventListener("click", enlargeme, false);
Aug 11 '09 #2
JulieQ
4
Thanks for the reply.
But if I embed this javascript, then I can direct this enlarged image to the cell - it is working.:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.  <HEAD>
  4.   <TITLE> New Document </TITLE>
  5.   <META NAME="Generator" CONTENT="EditPlus">
  6.   <META NAME="Author" CONTENT="">
  7.   <META NAME="Keywords" CONTENT="">
  8.   <META NAME="Description" CONTENT="">
  9.  </HEAD>
  10.  
  11.  <BODY>
  12.   <TABLE BORDER=1 WIDTH=70%>
  13.   <TR>
  14.   <TD>
  15.      <TABLE BORDER=1 WIDTH=100%>
  16.          <TR>
  17.            <TD><a href="dress1.gif"
  18.           onclick="bigPic=document.getElementById('clicpicLg482'); 
  19.           bigPic.src='dress1.gif'; bigPic.width=400; bigPic.height=300; 
  20.           return false;"><img src="dress1.gif" width="72" height="72" hspace="2" border="0" style="border:0px ridge white" src="dress1.gif"></a></TD>
  21.  
  22.            <TD><a href="dress1.gif"
  23.           onclick="bigPic=document.getElementById('clicpicLg482'); 
  24.           bigPic.src='dress1.gif'; bigPic.width=400; bigPic.height=300; 
  25.           return false;"><img src="dress1.gif" width="72" height="72" hspace="2" border="0" style="border:0px ridge white" src="dress1.gif"></a></TD>
  26.  
  27.          </TR>
  28.  
  29.          <TR>
  30.            <TD><a href="dress1.gif"
  31.           onclick="bigPic=document.getElementById('clicpicLg482'); 
  32.           bigPic.src='dress1.gif'; bigPic.width=400; bigPic.height=300; 
  33.           return false;"><img src="dress1.gif" width="72" height="72" hspace="2" border="0" style="border:0px ridge white" src="dress1.gif"></a></TD>
  34.  
  35.  
  36.           <TD><a href="http://www.isdntek.com/tagbot/misc/dustyroses.jpg";
  37.           onclick="bigPic=document.getElementById('clicpicLg482'); 
  38.           bigPic.src='http://www.isdntek.com/tagbot/misc/dustyroses.jpg'; bigPic.width=300; bigPic.height=300; 
  39.           return false;"><img src="http://www.isdntek.com/tagbot/misc/dustyroses.jpg" width="72" height="72" hspace="2" border="0" style="border:0px ridge white" 
  40.           src="http://www.isdntek.com/tagbot/misc/dustyroses.jpg"  ></a></TD>
  41.  
  42.          </TR>
  43.      </TABLE>
  44.  </TD>
  45.  
  46.  <TD>
  47.    <TABLE>
  48.     <TR>
  49.             <td align="center" width="408" height="308">
  50.               <img src="http://www.isdntek.com/tagbot/misc/bambi.jpg" id="clicpicLg482"  width="300" height="300"
  51.               alt="Click to Enlarge" style="border:0px ridge white">
  52.             </td>
  53.     </TR>
  54.    </TABLE>
  55.  </TD>
  56.  </TR>
  57.   </TABLE>
  58.  
  59.  </BODY>
  60. </HTML>
Aug 11 '09 #3
JulieQ
4
basically I can not put getelementbyId() into the PHP script - it is PHP script in the main body. It is always failure...

thanks,
Aug 11 '09 #4
Dormilich
8,658 Expert Mod 8TB
@JulieQ
that’s why javascripts are often put into external files—completely unaffected by any server scripts (and it’s way better to maintain, too)

btw, Welcome at Bytes.com

please use [CODE] // source code comes here [/CODE] when posting code
Aug 11 '09 #5
JulieQ
4
can you somehow make it work? it is still not working, even i put outside my script....
Aug 17 '09 #6
Dormilich
8,658 Expert Mod 8TB
@JulieQ
you have to be aware that you have to delay the event assignment until the body finished loading… I’ll look into it.
Aug 18 '09 #7
Dormilich
8,658 Expert Mod 8TB
there you have a working example to go on. I know that there are some limitations, but it shows you the general course of action.
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  4.     <head>
  5.         <meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" />
  6.         <title>test centre</title>
  7. // <![CDATA[
  8. // one function of my personal library
  9. function createCustomElement(name, text, attr) 
  10. {
  11.     // create element and its text content
  12.     var CE = document.createElement(name);
  13.     var TN = document.createTextNode(text);
  14.     CE.appendChild(TN);
  15.  
  16.     // attach attributes listed in attr object
  17.     for (var j in attr) 
  18.     {
  19.         var CA = document.createAttribute(j);
  20.         CA.nodeValue = attr[j];
  21.         CE.setAttributeNode(CA);
  22.     }
  23.  
  24.     return CE;
  25. }
  26.  
  27. function show()
  28. {
  29.     // create <img> with fixed values
  30.     var pic = createCustomElement("img", "", {src: this.src, width: 200, height: 200, alt: "zoomed image"});
  31.  
  32.     // target element
  33.     var frame = document.getElementById("enlarge");
  34.  
  35.     // remove previous images
  36.     while (frame.firstChild)
  37.     {
  38.         frame.removeChild(frame.firstChild);
  39.     }
  40.  
  41.     // insert new image
  42.     frame.appendChild(pic);
  43. }
  44.  
  45. // wait until document finished loading
  46. window.onload = function() {
  47.     // get all images to enlarge
  48.     var NL = document.getElementsByClassName("zoom");
  49.  
  50.     // obviously you can put this in a loop
  51.     NL[0].addEventListener("click", show, false);
  52.     NL[1].addEventListener("click", show, false);
  53. }
  54. // ]]>        
  55.         </script>
  56.     </head>
  57.     <body>
  58.         <div>
  59. <!-- style='border:0px ridge white' => style='border:0' -->
  60.             <img src='http://www.isdntek.com/tagbot/misc/dustyroses.jpg' width='72' height='72' style='border:0' class="zoom" />
  61.         </div>
  62.         <div>
  63.             <img src='http://www.isdntek.com/tagbot/misc/apples.jpg' width='80' height='60' style='border:0' class="zoom" />
  64.         </div>
  65.         <div id="enlarge"/>
  66.     </body>
  67. </html>
Aug 18 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Max Quordlepleen | last post by:
Apologies for the crossposting, I wasn't sure which of these groups to ask this in. I have been lurking in these groups for a week or so, trying to glean what I need to design a simple, clean...
6
by: TJ | last post by:
I've got a calendar that is based on the concept of lots of blocks that are spans with float:left. I would like to be able to have a detail section on the right side of the screen, so that when...
10
by: Florian Brucker | last post by:
There are several tutorials on the net showing you how to create a thumbnail gallery with floating thumbails which automagically uses all horizontal space available (e.g....
2
by: ted | last post by:
Hi, Was wondering if it's possible to find the left position of a table cell if the cell is created dynamically. I have a table with a single cell. When a button is clicked, I'd like to add...
6
by: Stevie D | last post by:
Hi I'm a Javascript newbie I'm doing a 'simple' (basically adding pages and changing text in frontpage 2000) update of a web site for a friend - what I have done 'should not' have done anything...
4
by: UJ | last post by:
I have a long list of items that the user will be able to select from. When they select an item, I'd like to have more detailed information appear on the right side of the screen. I've already got...
2
by: rudicheow | last post by:
SHORT VERSION ============= I have a bunch of identical fixed-size single-celled tables that rest against each other horizontally thanks to "float:left". These tables are dynamically generated...
4
by: ashasprabhu | last post by:
hai, I have to convert the images size into thumbnail and when the image is clicked the page is redirected and image should be enlarged.I tried to use the height and width property but the image is...
13
by: Casimir Pohjanraito | last post by:
I have a list of links, with a thumbnail image hidden(resized) next to the link. Complete html&css at end of this post. CSS for the link resizes the image on a:hover. All is good, except the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.