<p>
<input type="text" id="search" name="keywords" />
<input type="submit" value="Search" name="Submit" />
</p>
For the above code I was getting validation errors, but once I removed the id="search" the validation was good and error-free. I thought you needed an id, but I'm wondering if it is supposed to be there?
You do not need the ID attribute. The name attribute is the one that gets passed.
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.
Name is not a required attribute. A small quote from the HTML spec: The name content attribute gives the name of the form control, as used in form submission and in the form element's elements object. If the attribute is specified, its value must not be the empty string.
Do you have any other elements with that id in the document? That would be the only reason for validation to fail. IDs are meant to be unique in the document, if you have it elsewhere it would be invalid.
IDs are good when you plan on doing some sort of client-side work on the element, as an element that has an ID can easily and quickly be retrieved by Javascript. It is also good when you are using <label>
elements, as you can then use the for
attribute (which takes an ID) to point to the field.
Other than that, it doesn't really matter.
You do not need the ID attribute. The name attribute is the one that gets passed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With