473,608 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing Multiple Images with the Same Name

Hi All,

Just a quick question, which should have a simple answer...

Can I have a document with three images with the same name, and
reference those images individually.

ie:
<img name="picture" src="file1.jpg" >
<img name="picture" src="file2.jpg" >
<img name="picture" src="file3.jpg" >

Would I be able to refer to 'document.pictu re[2].src' and retrieve
'file3.jpg'?

I have tried this without success, and am hoping that you can educate
me on whether this is just poor syntax on my part, or whether I am
simply expecting too much of JavaScript...

Thanks
Luke
Jul 20 '05 #1
1 1980
is****@hotmail. com (Lucanus) writes:
Can I have a document with three images with the same name, and
reference those images individually.
Why give them a name if they are all the same?
Give them different names instead, or preferably, different ids.
Why not
<img id="picture1" src="file1.jpg" >
<img id="picture2" src="file2.jpg" >
<img id="picture3" src="file3.jpg" >
and
document.images['picture2'].src
ie:
<img name="picture" src="file1.jpg" >
<img name="picture" src="file2.jpg" >
<img name="picture" src="file3.jpg" >

Would I be able to refer to 'document.pictu re[2].src' and retrieve
'file3.jpg'?
That depends on the browser, and most likely not.
What you can do, if those three images are the only ones on the page, is
document.images[2].src

In most browsers, you should be able to do:
document.images['picture'][2].src
I have tried this without success, and am hoping that you can educate
me on whether this is just poor syntax on my part,


Not syntax, but the access method. You write "document.< name of
element>". That is not a good way to access an element. Instead you
should go through either one of the collections (like
document.images['picture']) or use another method to access elements
(like document.getEle mentsByName("pi cture")).

On top of that is the problem of having more than one element with the
same name, which should generally be avoided outside of forms.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

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

Similar topics

2
4721
by: michael nieuwenhuizen | last post by:
how do i create a sticky form with multiple fields? say i want a form with: name: address: country: and if a user presses the submit button it will show
2
8043
by: Simon | last post by:
Am using the following code. <script language="JavaScript1.2"> function setquantity(productindex,productquantity) { //create the reference object irefname_none = eval("document." + productindex + "none"); <snip>
4
1685
by: seven | last post by:
This might be a newbie question or otherwise easy stuff for some of you, but it's tweaking me ... can't seem to get it to work right. I am working with a script that basically creates two arrays, and with a single call in the html, randomly inserts a graphic (which is linked to another page, as defined in the second array). The working example is http://seven.postmodern.com/insight/tarot/1cardreading.html What I would like to do is...
2
1407
by: RWC | last post by:
Hello, I have a page connected to an SQL table. The page loops through, creating a row for each record, displaying in image, the ID of which is set to the record id. When I click a button to change the image, I'd like to refer to the ID on the main page, but change the image on the main page. Any idea how to do this? Example is as follows
0
2691
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main form. Then I have 3 pages on a tab control ( 4 if the type of candidate validates that is is to be shown) Each page has a subform. The subforms can be either single or continuous, I think I am still deciding what I want to lock down this entry...
2
4064
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I want to do this as I want to use same subform on two different parent forms. Main problem is that the subform is not part of the forms collection. The only workaround I found was setting the query in code in the
2
3830
by: Tom | last post by:
I need to be able to reference some images stored in my VB.NET program. Normally, I would load the images into an ImageList control and use them from there (these are going to be icons). However, I need to be able to add/delete images from this image 'store' (whatever I end up using); but because an image list only allows referencing by image number in the list, when I would delete an image/icon it would 'mess' up the ones following that...
21
5088
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main form, the code errors out at the 2nd line. The error number is 13 and the description is "Type mismatch". Both controls are memo fields. I suspect that "Screen.ActiveControl.Parent" is not referencing the form as intended. Thanks for any help,...
11
4152
by: Jankie | last post by:
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images. I only want 1 entry to display all of a user's related images like below: Id First Name Last Name Title Image1 Image2 Image3
0
8087
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8025
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8365
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1620
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1363
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.