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.
6 1986 acoder 16,027
Recognized Expert Moderator MVP
You can have two elements with the same name, but an ID should be unique.
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...
acoder 16,027
Recognized Expert Moderator MVP
If you give your input element the name "lastname", document.forms["form1"]["lastname"] should work.
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'.
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.
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: - divEl.getElementsByTagName("span")
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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....
|
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...
|
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...
|
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.
...
|
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
###############
...
|
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+,...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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: 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,...
|
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...
|
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...
|
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...
| |