note 85016 deleted from tutorial.forms by danbrown
| From: | danbrown@php.net | Date: | Thu, 15 Jan 2009 03:48:49 +0000 |
| Subject: | note 85016 deleted from tutorial.forms by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149228@lists.php.net to get a copy of this message | ||
Note Submitter: rosko at zeta dot org dot au
----
@Lord Pacal: the attributes 'name' and 'id' have different intent and are used
differently. 'id' uniquely identifies an element in the HTML DOM, whereas 'name'
identifies the field that will be transmitted on the form submit. You can omit the 'id'
attribute, but not the 'name' attribute.
Where a field requires multiple elements, e.g. radio buttons and check boxes, the 'name'
attribute must be the same but the 'id' must be unique for each element.
'id' is useful for linking explicitly to the element, as in the following cases:
* CSS selector by ID
* JavaScript code, e.g. in-browser form validation or active forms
* the target of a <label> element
The last example is one not used nearly enough, as it allows the user to click on the text next to a
radio button or check box - a bigger target and thus easier for users not used to using a mouse:
<input type="checkbox" name="example" value="yes"
id="example_yes"/>
<label for="example_yes">Yes, I can click on the text and check the
box</label>