View Single Post
Old 02-13-2013, 09:08 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
i had to make myself get into the habbit of doing id's in inputs wether i needed them or not, because i do use them quite a bit in js for validation of input and it is easier to have them in there...
There is never any reason to use IDs for input validation.

Compare this code (just showing the code needed to access four form fields, no validation):
Code:
var fld1 = document.getElementById("field1");
var fld2 = document.getElementById("field2");
var fld3 = document.getElementById("field3");
var fld4 = document.getElementById("field4");
versus this:
Code:
var form = document.getElementById("myForm");
var fld1 = form.field1;
var fld2 = form.field2;
var fld3 = form.field3;
var fld4 = form.field4;
Using the form and field names produces shorter code *and* faster code.

What's the excuse for using IDs?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote