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

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.picture[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 1953
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.picture[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.getElementsByName("picture")).

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/rasterTriangleDOM.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
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
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." +...
4
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,...
2
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...
0
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...
2
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...
2
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...
21
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...
11
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.