473,467 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Safari bug? Error when I have more then one element with the same id

11 New Member
This cannot be right.

I have two forms on one page. Both forms have an input element with the id="lastname". When I use a javascript to access theese input elements, I have to use

document.forms["form1"]["lastname"]

In IE, Firefox, and Opera, this works fine, because the two input elements are inside two different forms.
BUT: It does not work fine in safari.
What I do not understand is that Safari would not allow two elements with the same id in two DIFFERENT forms.
Nov 7 '07 #1
6 1986
acoder
16,027 Recognized Expert Moderator MVP
You can have two elements with the same name, but an ID should be unique.
Nov 7 '07 #2
Stale
11 New Member
Unique ID?

This is not only a form-input problem, but all elements on a page, Elements that cannot contain the name attribute (like <div>).

So thats why its not good enough. Many webpages, and more to come, are build up by external data, or by multiple webpages, created by different persons. So, when a javascript wants to access an element, it should be able to do so, if the scripts knows where to look. Like my example, the script knows it should look inside form1, and finds the element, in all major browsers except Safari...
Nov 7 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
If you give your input element the name "lastname", document.forms["form1"]["lastname"] should work.
Nov 7 '07 #4
drhowarddrfine
7,435 Recognized Expert Expert
As acoder said, ids are unique names to one element. If you must apply the same style/name to more than one element, use 'class'.
Nov 7 '07 #5
Stale
11 New Member
OK I get that.

But it does not resolve my problem.

Lets say you have an application wich are build up by several DIVSs. Inside every DIV you have several SPANs, and you want to change the innerHTML of one or more of the SPANs. The SPANs has id attributes, but the id can be the same as an id inside one of the other DIVs.

This is easy, because you will access the SPAN you wish, by first accessing the DIV and then access the SPAN inside that DIV.

And this is what is working on IE Firefox and Opera but NOT in Safari.
Nov 9 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
Lets say you have an application wich are build up by several DIVSs. Inside every DIV you have several SPANs, and you want to change the innerHTML of one or more of the SPANs. The SPANs has id attributes, but the id can be the same as an id inside one of the other DIVs.

This is easy, because you will access the SPAN you wish, by first accessing the DIV and then access the SPAN inside that DIV.
An ID should be unique otherwise document.getElementById() is undefined.

If you want spans within a div try:
Expand|Select|Wrap|Line Numbers
  1. divEl.getElementsByTagName("span")
Nov 9 '07 #7

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

Similar topics

3
by: Roger Withnell | last post by:
My simple popup menu code works in IE (Windows and Mac) but not in Safari. I use a onmouseover ShowMenu function and a onmouseout HideMenu function. Because Safari, unlike IE, recognises...
2
by: Lutz Ißler | last post by:
Hi all! I dymically replace the child nodes of a DIV element by image nodes. In IE and Firefox this works properly. In Safari it works properly, too - but only if the site is called locally, eg....
5
by: Bill Cohagan | last post by:
I'm having some serious difficulties with my ASP.Net 2.0 app rendering in Safari 2.0.3. The most immediate problem is that the menu control doesn't seem to work at all, particularly the use of...
8
by: dd | last post by:
Hi, I've discovered a scenario where Safari 1.3 (I need to make my stuff compliant with 1.3+) gets confused about the scope of local variables WITHIN functions that were created in dynamic...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
7
by: khinester | last post by:
Hello, I have the following template that basically does the following: User select Country, then a sub-list is generated with Regions and then this returns the Counties ############### ...
11
by: Stevo | last post by:
I've been using the unload event for a long time. I have this code, which I've abstracted and made into a stripped down simple test case below, and it works fine on the major browsers (IE5+,...
7
by: David Stone | last post by:
Run into something recently that has left me a little puzzled. According to the examples in section 13.6.1 of html 4.01... <http://www.w3.org/TR/html401/struct/objects.html#h-13.6.1.1> I...
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
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...
0
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,...
0
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.