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

NAME and ID attributes are identical.???

I'm hoping I understand this bit correctly:
>>>>>>>>>>>>>>> http://www.jibbering.com/faq/faq_notes/form_access.html
When writing HTML that conforms to a DTD that allows FORM elements to
have NAME attributes it is possible to also give the FORM element an ID
attribute that corresponds with its NAME attribute (so long as the ID
is unique on the page). The form will appear as a member of the
document.forms collection under a property name that corresponds with
the value of the NAME and ID attributes (as they are identical).>>>>>>>>>>>>>>>


Does that mean that if I went through all my forms tonight and changed
every NAME attribute to ID, pretty much nothing would happen? My
Javascript would work the same, as if nothing had changed? And when
those forms were submitted to the server, and interacted with PHP, PHP
would find the form inputs, it doesn't matter if those inputs have ID
or NAME???

Jul 23 '05 #1
6 1599
lk******@geocities.com wrote:
Does that mean that if I went through all my forms tonight and changed
every NAME attribute to ID, pretty much nothing would happen?


No, only name is important for submitting form data. The id is for client
side stuff only.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2
Ivo
<lk******@geocities.com> asks
I'm hoping I understand this bit correctly:
http://www.jibbering.com/faq/faq_notes/form_access.html
<snip>
Does that mean that if I went through all my forms tonight and changed
every NAME attribute to ID, pretty much nothing would happen? My
Javascript would work the same, as if nothing had changed? And when
those forms were submitted to the server, and interacted with PHP, PHP
would find the form inputs, it doesn't matter if those inputs have ID
or NAME???

That 's right, yes it would, and no it does matter. :)
The form itself will be happy to be id'ed instead of name'd, but the form
elements, ie. the input, select, textarea or other such objects inside the
form should still have a name if their name-value pairs are to submitted to
the server in the usual way.
--
Ivo
http://www.vansandick.com/

Jul 23 '05 #3
VK
NAME is a legacy attribute. It was introduced in forms at those prehistoric
times then no one thought about DOM, DHTML, XML etc.
Later 3W decided to keep the "name" as a valid primary naming attribute for:

forms
form elements
images
links
anchors

What allowed to keep gigs of existing code of being valid without major
rewriting (and without changes in form submission mechanics).
So with these 5 elements you should follow the old "NAMEing" tradition. With
any other elements you should use the modern "IDfication".

Also important to notice, that by the current 3W standards NAMEs and IDs are
sharing the same name space.
Two consequences of it:

[1] You must use either NAME or ID, but not the both.
<form name="myFormName" id="myFormID"> is equally pointless and error prone
as
var myVar="value1"; var myVar="value2";
or
var myVar, myVar = "value";

[2] ID is ruled by the common variable naming rules. NAME is of CDATA type
(briefly meaning any imaginable combination of characters). But as they are
sharing the same name space, browser has to serve the "biggest possible
request", which is CDATA in this case. As a result, naming rules for IDs
existing only on the paper. In the reality you can use any CDATA for IDs:
'{!!!!-My Greetings to 3W:-)---}'
will work as well as
'myCorrectID'
(I hope you'll not jump too heavily on this opportunity though.)


Jul 23 '05 #4
VK
To make it easier to accept:
think of plural exceptions in English:

parent - parents
father - fathers
mother - mothers
child - children

Is 'children' an exeption? Surely! But try to tell me that the correct
modern form should be 'childs'.

Jul 23 '05 #5
On Fri, 10 Dec 2004 12:22:48 +0100, VK <sc**********@yahoo.com> wrote:

[snip]
forms
form elements
images
links
anchors
[snip]
So with these 5 elements you should follow the old "NAMEing" tradition.
No. With form controls that are to be submitted, use the name attribute.
With all other elements, including form controls that are not to be
submitted, use the id attribute. The only exception to this rule is if you
want to (or need to) support NN4 (or similar) which doesn't include id
support.

[snip]
Also important to notice, that by the current 3W standards ^^
W3C :P

[snip]
[1] You must use either NAME or ID, but not the both.
That's also incorrect. You can use both but, with the exception of form
controls, the values must be the same.

[snip]
[2] ID is ruled by the common variable naming rules. NAME is of CDATA
type (briefly meaning any imaginable combination of characters). But as
they are sharing the same name space,
They only share the same name space when they are used for anchor names.
browser has to serve the "biggest possible request", which is CDATA in
this case. As a result, naming rules for IDs existing only on the paper.
In the reality you can use any CDATA for IDs:
'{!!!!-My Greetings to 3W:-)---}'
will work as well as
'myCorrectID'
(I hope you'll not jump too heavily on this opportunity though.)


Don't do it at all! Just because you *can* do things doesn't mean you
should. Taking that approach will produce invalid HTML and you might be
surprised if a user agent decides to ignore that attribute, or modify the
value (not that I suspect any do...).

The legal characters that compose the ID data type are perfectly
reasonable, and there is no reason to make a document invalid just to
include some other character. Don't forget that ids have several purposes,
not just limited to scripting.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
VK wrote:
They should stop to be fussy-pussy for a second, and just make form (and
form elements) an official exception from IDfication
I disagree. Keeping bad design around just because it is there now isn't a
good idea.
(child - children, why - because of the history issues).
The English language grows organically. (X)HTML is _designed_ and has
_versions_. You can't compare them.
I don't like the situations then "this is right, and this is right too,
and this may be right too sometimes, etc."


Its more like: "This is not right. This is right. You may want to use both
during the transitional phase while user agents catch up."

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #7

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

Similar topics

1
by: Gooseman | last post by:
Hi Just getting into XSD and have some questions: If I have several different elements that all have identical attibutes, what is the best way of conveying that in the XSD? Is there a way...
5
by: Neville310 | last post by:
I have a few questions about the name attributes and href referencing to. Can you declare name attributes for tags other than anchor elements (like div or h2)? The validator keeps returning the...
1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
3
by: gogaz | last post by:
Hi, I am new to XML. Is following XML write? Or it can cause errors for other developers using/parsing my XML output in their respective applications. <emp id="101" name="ABC">...
5
by: Flipje | last post by:
In my view, there is a major drawback to using attributes: the getter and the setter have identical protection levels. But I usually want the getter to be public and the setter to be protected or...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
16
by: digitalorganics | last post by:
What's the difference between initializing class variables within the class definition directly versus initializing them within the class's __init__ method? Is there a reason, perhaps in certain...
19
by: Kirk Strauser | last post by:
Given a class: how can I find its name, such as: 'foo' I'm writing a trace() decorator for the sake of practice, and am trying to print the name of the class that a traced method belongs...
11
by: CJM | last post by:
I have a bit of code that inserts some extra controls (specifically, ordinary <input type="hidden" name="MyField"form fields) into an existing HTML form. However, it is mangling the name & IDs of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.