Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12467

Re: Referring to Controls by id

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Referring to Controls by id
Date 2012-03-07 10:44 +0200
Organization A noiseless patient Spider
Message-ID <jj774j$emf$1@dont-email.me> (permalink)
References <191dl7ltuts723trrgoj29mln2b3uvqflk@4ax.com> <en2dl7ttlc120rthego0g2fuspsu73c9k3@4ax.com> <hg5dl7pk5ot1s5nvl2ob3t1vi8p4jldea6@4ax.com> <0l2el71nm2p6f9rfh4vjmlj8urgalag41d@4ax.com>

Show all headers | View raw


2012-03-07 10:08, Jeff North wrote:

> If you want to write
> <input name='fred' id='fred'>
> and only want to use
> <input name='fred'>

... then stop wanting that. :-)

> then why not use some script to assign an id to each control. That way
> you have less typing and, if js is turned off, then the forms will
> submit as per normal.

But any CSS styling that uses id selectors is lost, among other things.

There are good reasons to use an id attribute for every form field:
1) Handy for referring to the element in JavaScript.
2) Handy for referring to the element in CSS. The id selectors work 
universally, e.g. attribute selectors don't.
3) Needed for associating a field with its <label> in the general case. 
(You can put <input> inside <label> instead, but it's less natural and 
it's not possible e.g. when <label> is in one cell of a table and 
<input> is in another cell.)

For text input fields, you can almost always use the same string in the 
id value as in the name value. For radio buttons, you cannot, but it is 
usually easy to apply some simple naming scheme. And if you have 
zillions of fields to generate, you are probably doing it 
programmatically anyway, so it's just a matter of a little extra coding.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 14:03 -0800
  Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 09:23 +1100
    Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 15:02 -0800
      Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 19:08 +1100
        Re: Referring to Controls by id "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-07 10:44 +0200
          Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 23:32 +1100
      Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-07 21:26 +0000
  Re: Referring to Controls by id Denis McMahon <denismfmcmahon@gmail.com> - 2012-03-07 01:31 +0000
    Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 22:33 -0800
      Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-08 19:06 +0000
    Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-07 10:26 +0000
      Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-07 08:55 -0800
        Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-08 09:44 +0000
          Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-08 19:26 -0800

csiph-web