HTML Naming Standard?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply

Do you have an HTML naming standard?

Yes
3
50%
No
2
33%
Working on it
1
17%
 
Total votes: 6

User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

HTML Naming Standard?

Post by Buddha443556 »

What standards do you use for naming your controls?

Code: Select all

<input type="text" name="txtTitle">

Code: Select all

<select name="lstGroups">
What about IDs? Same namespace (in HTML4 at least).

Code: Select all

<select id="lstGroupsID" name="lstGroups">
Make any exceptions for password/username to work with browsers auto complete features?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I don't really understand the question :oops:

I wasn't aware the ID's and Name's shared the namespace in HTML4, so I've learned something new there. I'll almost always give an element an ID that matches it's name (!!).

I try not to name my form elements after the database fields they relate to. I'm sure it's hardly a security implication since it would just be secuirty through obscurity but I just feel more comfortable keeping that information private. Like I say, not sure what the question is :P
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

I don't really understand the question
Got a standard for naming your classes, methods, properities or variables? In a desktop application, you would have some sort standard for naming the GUI controls right? Same sort of thing and for about the same reasons. Eventually in PHP what we name our controls winds up in out PHP code itself usually as an array index. Well, I've actually found little reference to such standards for HTML (or PHP) which is why I asked.
I'll almost always give an element an ID that matches it's name (!!).

I try not to name my form elements after the database fields they relate to. I'm sure it's hardly a security implication since it would just be secuirty through obscurity but I just feel more comfortable keeping that information private. Like I say, not sure what the question is
That's sort of a standard right there.
From: http://www.softlookup.com/tutorial/interdev/ch12.asp

Q. Why should I adhere to standard naming conventions for my controls

A. Without standards, there would be chaos. Seriously, though, standard naming conventions help provide descriptive names for your controls. The most important advantage to using standard prefixes for your control names is that they enable you to easily identify the type of control being used. The prefix also makes it easier to read and understand your code.

For example, the control name CreditCard doesn't tell you what type of control is being used. It could be a text field, a radio button, or some other type of control. The nonstandard name relies on your memory of the control type to properly use it in your code. If you use the standard name optCreditCard, then you know that the control is a radio button, so you can use the correct tags, attributes, and code for a radio button control.
From: http://jibbering.com/faq/faq_notes/form_access.html

Because ECMAScript is case sensitive it may only be necessary to capitalise the name of the INPUT element to avoid the conflict. However, it would probably be safest to adopt a naming convention for form controls that ensured that they do not correspond with existing properties of the FORM elements regardless of case. Especially as theW3C HTML specification implies that referring to named properties of collections can be case insensitive in HTML DOMs. In reality I don't know of any implementations in which it is but it would be better to err on the side of caution.
Weird topics must be my thing around here. :oops:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Buddha443556 wrote:
From: http://www.softlookup.com/tutorial/interdev/ch12.asp

Q. Why should I adhere to standard naming conventions for my controls

A. Without standards, there would be chaos. Seriously, though, standard naming conventions help provide descriptive names for your controls. The most important advantage to using standard prefixes for your control names is that they enable you to easily identify the type of control being used. The prefix also makes it easier to read and understand your code.

On server side it would be strings regardless of the type of input elements... therefor... I don't see any reason to use type prefixes.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Weirdan wrote:On server side it would be strings regardless of the type of input elements... therefor... I don't see any reason to use type prefixes.
Documentation? Readability? Maintainability? Keep you or your successor from digging through a bunch of templates to find out what kind of control the string is related? Of course, you have a point, it's just a string which is also the easiest way to deal with it and there's nothing wrong with that.
Post Reply