Solved

AutoResize images inside of table?

Posted on 2003-11-19
2
292 Views
Last Modified: 2012-06-27
Hi everyone -

I have the following code that will automatically resize all images on a page to a desired size:


****************************
      <head>
            <script language="javascript">
            <!--
                  function sizeIt() {
                        for (i=1;i<document.images.length;i++) {
                              if (document.images[i].width > 100) {
                                    document.images[i].width = 100;
                              }
                        }
                  }
            //-->
            </script>
      </head>

                <body onLoad="JavaScript: sizeIt();">
                                <P><IMG alt="" src="emailTag.jpg"></P>
                                etc...
                </body>
****************************


This works fine for all images on the page, but I am trying to resize only the images within a table (image gallery).  I am wanting it to resize these images within the table to use as thumbnails (then click it to open the full size image).

I'm thinking I could do a function where I pass a reference of the image to the function and it could do something like:

****************************
function sizeIt(imageReference) {
      if (imageReference.width > 100) {
            imageReference.width = 100;
      }
}

and

<IMG alt="" src="emailTag.jpg" onLoad="JavaScript: sizeIt(this);">
****************************

However, as I'm sure you can tell, I'm not a JavaScript guy at all (spend most of my time server-side with .NET and SQL), and so my syntax and thoughts aren't quite in a row.

Any help would be greatly appreciated!

Thanks in advance,
-chris

0
Comment
Question by:pillbug22
2 Comments
 
LVL 1

Accepted Solution

by:
FragMaster_B earned 100 total points
ID: 9780393
You can get a collection of all images in a table via this method. (This assumes your table has an ID attribute of "myTable".)

[code]
var imgColl = document.getElementById("myTable").getElementsByTagName("IMG")
[/code]

Once you have this collection, you can itterate through it basically the same way you do above.

[code]
for (LC=0; LC<imgColl.length; LC++) {
    if (imgColl[LC].width > 100) {
        imgColl[LC].width = 100;
    }
}
[/code]

Hope this is what you're looking for,
Frag
0
 
LVL 6

Author Comment

by:pillbug22
ID: 9780492
Ahhhh...beautiful.....

thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question