Reputation: 265
I have a web form that have 5 radio button with the same id.
How can I catch all the radio buttons in a vector from JavaScript?
Upvotes: 2
Views: 4762
Reputation: 18790
Element identifiers: the id = name [CS] This attribute assigns a name to an element. This name must be unique in a document. The id attribute assigns a unique identifier to an element (which may be verified by an SGML parser).
The id attribute has several roles in HTML:
As a style sheet selector. As a target anchor for hypertext links. As a means to reference a particular element from a script. As the name of a declared OBJECT element. For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).
http://www.w3.org/TR/html401/struct/global.html#adef-id
Upvotes: 0
Reputation: 1258
You should use different ids or different names for html elements. Also jquery helps you on this subject.
$(':radio')
it helps you to select all radio elements on the page. You can do what you want with using Jquery.
here is the jquery source: http://code.jquery.com/jquery-1.4.2.min.js
Upvotes: 3
Reputation: 21
Using same ID for more than one element on page is incorrect! use name
attribute to group these buttons.
Upvotes: 2