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

A couple of tricky image issues

Dear All,

I'm kocking together a page along the following lines...

<DIV ID="container">
<DIV ID="thumbs"><IMG SRC="..."><IMG SRC="..."><IMG SRC="..."></DIV>
<DIV ID="mainimage"><IMG SRC="..." NAME="bigimage"></DIV>
</DIV>

Could anyone give me some clues as to how to change the src of
bigimage? document.bigimage.src obviously wont do it because of the
nested DIVs. Any other route?

Also, some of the images that could go into bigimage are of different
proportions - can I stop them stretching to the size of the original?

Any advise taken very very gratefully.

Dan

Feb 24 '06 #1
5 980
da*******@hotmail.com wrote:
Dear All,

I'm kocking together a page along the following lines...

<DIV ID="container">
<DIV ID="thumbs"><IMG SRC="..."><IMG SRC="..."><IMG SRC="..."></DIV>
<DIV ID="mainimage"><IMG SRC="..." NAME="bigimage"></DIV>
</DIV>

Could anyone give me some clues as to how to change the src of
bigimage? document.bigimage.src obviously wont do it because of the
nested DIVs. Any other route?


If, instead of (or in addition to) a name, you give an id, then you can
use document.getElementById:

<IMG src="..." id="bigimage">

document.getElementById('bigimage').src = "...new src..."

Csaba Gabor from Vienna

Feb 24 '06 #2
annother way is:
var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++)
{
var img = imgs[i];
if (img.name = "bigimage")
{
img.src = "....";
break;
}
}

Feb 24 '06 #3
d
<yu********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
annother way is:
var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++)
{
var img = imgs[i];
if (img.name = "bigimage")
{
img.src = "....";
break;
}
}


Letting the browser's native code do the work will be a lot quicker than
iterating through a collection of images... getElementById() is the way
forward :)
Feb 24 '06 #4
da*******@hotmail.com said the following on 2/24/2006 6:56 AM:
Dear All,

I'm kocking together a page along the following lines...

<DIV ID="container">
<DIV ID="thumbs"><IMG SRC="..."><IMG SRC="..."><IMG SRC="..."></DIV>
<DIV ID="mainimage"><IMG SRC="..." NAME="bigimage"></DIV>
</DIV>

Could anyone give me some clues as to how to change the src of
bigimage? document.bigimage.src obviously wont do it because of the
nested DIVs. Any other route?
Says who? Did you test it? The nested DIVS are irrelevant to the images
collection:

document.images['bigimage'].src=newImage; will work.
Also, some of the images that could go into bigimage are of different
proportions - can I stop them stretching to the size of the original?


Give your img tags a width and height.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 24 '06 #5
Csaba Gabor wrote:
<snip>
If, instead of (or in addition to) a name, you give an id,
then you can use document.getElementById:

<IMG src="..." id="bigimage">

document.getElementById('bigimage').src = "...new src..."


The commonly (near universally) implemented, and W3C DOM standard,
convenience - document.images - collection is the place to quickly look
up references to images by name (and/or ID in modern browsers) in HTML
DOMs.

Richard.
Feb 24 '06 #6

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

Similar topics

5
by: Alper Adatoz | last post by:
Hi, i have a little problem. i hope u guys give me a clear solution (: db: mssql i just want to put jpeg file to the image field at the mssql db. and after that i want to call it back..
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: Giggle Girl | last post by:
Overall Background: I am in charge of migrating an already-made Content Mangement System from ASP to PHP. I do not know PHP -- yet! I am trying to foresee potential issues, and here is one. ...
3
by: Viken Karaguesian | last post by:
Hello all, I need somehelp with background tiling. I have a sneaking suspicion that what I want to do is not possible, but I'll ask anyway. :>) First some background: Here's the site in...
6
by: abdullah1983 | last post by:
Hi Guys, I need some clarification regarding the problem with safari browser. Please find my code below. I'm setting the image src, mouseover and mouseout using javascript. The mouseover and...
2
by: webonomic | last post by:
Converting data types I'm trying to do some image manipulation. This code project article (http://www.codeproject.com/csharp/imageresize.asp) has a great method I want to modefy. Here it is: ...
2
by: reynardmh | last post by:
I tried to change the image.src on the fly when the user click a link. But for some reason it does not work in IE 6 (the image just disappear when I click the link), but if I add the alert('test')...
2
by: | last post by:
I have a few custom controls that expose properties of type Image. The built in controls that have Image properties allow you to delete the image and set it back to "None". How can I allow my own...
17
by: Liam Gibbs | last post by:
Hello everyone, I'm having a problem with a site I'm building. It uses tables, but it's really tricky. A picture of the layout I need can be found at http://www.altmarvel.net/Liam/WHATINEED.jpg...
5
by: Michael | last post by:
Hello all, how could I rotate a server side image in asp.net and show it in web page? Thanks.
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.