From: Adam Richardson

> On Wed, Jun 30, 2010 at 9:16 PM, David Mehler <>
>> Hello,
>> I've got a php form processing question. I've got a text field like
>> <div>
>> <label for="txtname">Name*:</label>
>> <input type="text" name="name" id="name" size="30" value="<?php echo
>> htmlspecialchars($_POST['name']), ENT_QUOTES, UTF-8; ?>" /> <br />
>> </div>
>> My question is what is the purpose of the id field? I know the name
>> field is what php references, but am not sure what id is for?
> Sometimes it's helpful to target a specific element for stylistic or
> functional purposes, and that's when you'll find an id attribute
> In your example above, label elements use the id in the 'for'
> (and, speaking to your example, you should have for="name" instead of
> for="txtname"):
> In terms of CSS, you can specifically reference the element by it's id
> the notation tag_name#id_value, and id's have the highest order of
> specificity (i.e., if you try and style an element by tag name, class,
> and/or id, the id styles are what will take precedent, all other
> equal.)
> In terms of javascript, you can reference the element by it's id by
> the function getElementById('id_value):
> Just remember that a particular id can only occur once on a page
> difference between the name attributes in a form, as you could have
> forms on a page and each form could have an input with a "zip" name
> issue, but that same page could only have one id with the value
> That all said, with the advent of javascript data attributes, you'll
> one more way to target elements for design and functionality:

If you look at the current HTML 4.01 and XHTML 1.0 specification, you
will find 'name' is no longer listed as a standard attribute. It is all
but obsolete and has been replaced by 'id' almost everywhere. They
actually recommend you put both attributes into tags with identical
values until your applications can be updated to drop all uses of the
name attribute.


Bob McConnell

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to