Gérard Talbot said the following on 3/16/2006 12:07 AM:[color=blue]
> Randy Webb wrote :[color=green]
>> Gérard Talbot said the following on 3/15/2006 10:53 PM:[color=darkred]
>>> Matt Kruse wrote :
>>>> Crazy Code Ninja wrote:
>>>>> getElementById is really the preferred way
>>>>
>>>> Not really. Then you need to generate a unique ID for each input field
>>>
>>>
>>> This is exactly what the HTML 4.01 recommendation says, btw:
>>> "Applications should use the id attribute to identify elements."
>>>
http://www.w3.org/TR/html401/interac...adef-name-FORM[/color]
>>
>> I don't think my thoughts about the specs need to be repeated.[/color]
>
> I do not keep a log of what everyone says about this or that... so you
> may have to repeat... and I'm getting old too :)[/color]
I have read the specs so many times that when I see people quote them I
almost know where to go find it before they tell me. But I still
wouldn't give you 10 cents American for all of them. They are a good
guideline but that is it. I prefer to know what the Browser's behavior
is compared to what it should be :)
[color=blue]
>
> But, for[color=green]
>> curiosity sake, give all your form elements an id with no name, submit
>> it to the server, and let us know what you get?[/color]
>
> Of course, it does not make sense. Name/value pairs of form controls are
> submitted to the server: that's why name was not deprecated for input,
> select and form controls submitting data.
> Maybe I may have totally misunderstood that quote from the spec. The
> quote might refer only to the form element, not to its contained
> elements. I don't know.[/color]
From reading that section, and then the section following it on inputs,
I would say it is definitely in relation to the FORM element itself and
not its elements.
<!ENTITY % InputType
"(TEXT | PASSWORD | CHECKBOX |
RADIO | SUBMIT | RESET |
FILE | HIDDEN | IMAGE | BUTTON)"[color=blue]
>[/color]
<!-- attribute name required for all but submit and reset -->
And then in the attlist there is no ID. But further below that it says
"Attributes defined elsewhere" and lists the ID.
So, since it says that form elements are required to have a name it
wouldn't make sense for them to be deprecated :)
<snipped things we appear to agree on>
[color=blue][color=green]
>> But, to use XHTML as a defense/reason to use the ID on a form instead
>> of the NAME isn't a good argument.[/color]
>
> No, it's the other way. If you're using XHTML, then you can't "name"
> your form. You have to access your form with the ordinal index.[/color]
Or it's ID :)
[color=blue]
> So, using the ordinal index instead of the name attribute is more code
> portable. That's all I'm saying. I don't necessarly want to promote
> XHTML... but then again, there are people who (rightly or wrongly) use
> XHTML.[/color]
I think both of our opinions are right and both are wrong. The solution
is what best fits the situation :)
[color=blue]
> Witness IE's behavior with XHTML. (I[color=green]
>> know, people reply with "content negotiation").
>>[color=darkred]
>>> So, unless you're using lots of forms in a single page (why would you
>>> need several forms in the same page is beyond my comprehension),
>>> using indexes is not a big deal.[/color]
>>
>> Multiple forms on the same page have there uses. What if you wanted a
>> search engine portal for 10 different search engines? You would have
>> 10 different forms so you could post them to 10 different search engines.
>>[/color]
>
> It's rather rare webpage situation... don't you think?[/color]
Probably so. When I wrote that I was thinking about a page I wrote for a
friend that orders parts. He has 11 vendors he uses and has to search
all 11 one at a time. I wrote him one that combines them all into one
page. But, it has 12 different forms it uses so he can search
individually and a "search them all" form. But for a web situation, the
most I have seen in practical use is 4 - my bank's website. It has one
for me to login, it has a Google search box (why I want to go to my
banks site to search Google is beyond me though), one for me to contact
the webmaster if I can't login and the fourth is a "I lost my password"
form.
[color=blue]
>[color=green][color=darkred]
>>> Matt, you propose *best* javascript practices that, in my humble
>>> opinion, are not as portable as they can be.... at least, on this
>>> name versus index issue.[/color]
>>
>> And if someone comes along behind you and adds a form before this one,[/color]
>
> This makes no sense to me. Unless several several people are developing
> a same single website. Again, this is not common.
> In a workplace, when coding practices are defined, this sort of issues
> is explicited for all people adding code or removing code. Usually, only
> 1 person does make change and he documents these.[/color]
I want your job then. I don't get assignments that say "Here is the
page, this is what I need". It's more along the lines of "I want a
snippet/widget that does this, here's your deadline, here's your money,
where's my damn code".
[color=blue][color=green]
>> it breaks your code. With a name/ID attribute, that doesn't happen.
>> Which one is the better practice? There is no ambiguity with
>> document.forms['formID'] when there is with document.forms[#]
>>[/color]
>
> There is room for ambiguity *if* you have more than 1 form element, *if*
> someone else is adding another form *before* without noticing the form
> issue. I'd say right here that this is extraordinary rare.[/color]
I don't. But it still goes back to "The best solution depends, directly,
on the situation". And if you want a "General Best Practice", you either
use the forms NAME or ID to access it. Then, it works in *all*
situations where the form has a NAME/ID.
[color=blue][color=green][color=darkred]
>>> Best practices should always promote valid, safe, sound practices
>>> which will work reliably across browser, across different DTDs and
>>> across code context.[/color]
>>
>> That alone makes the forms['formID'] a better practice than forms[#].
>> But, if it is going to be "across different DTD's" then you have to do
>> something different. Does HTML3.2 allow ID's on forms?[/color]
>
> I didn't propose id for forms.[/color]
Not directly. You said "Best practices should always promote valid,
safe, sound practices " and that makes forms['formID'] a better -
general - practice than forms[#] because it will work in more situations
than forms[#] will. That was my only point.
[color=blue]
> One thing is for sure: best javascript practices - whatever they are -
> should work in strict DTD (HTML 4.01 or XHTML). Coding for transitional
> DTD is already not the best markup coding practice. Best javascript
> practices has to be harmonized, coherent, consequent with (and based on)
> best markup coding practices to begin with.[/color]
I totally agree. But there still has to be a limit somewhere. Otherwise,
you lose the ability to keep a document "general" in scope. I had a
conversation with Richard a long time ago about this same thing. I wish
I could find the thread but I can't. But it was based on best practices
in general and the example that I used was changing the source of an
image. I can write for weeks on end about pre-loading, changing, and
loading images and would probably still miss some of the caveats and
problems with it. But to stay general, you have to limit yourself
somewhere and say "This is it". You change the source of an image by
using the images collection and changing it's src property. This is the
same principle. Somewhere, somehow, you have to limit yourself or you
end up making your guidelines so convoluted that you lose your general
audience by making it *too* complex by including all the caveats/problems.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Please quote what you are replying to.
If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers. <URL:
http://www.safalra.com/special/googlegroupsreply/ >