views:

42

answers:

3

I have an web form that have 5 radio button with the same id. how i can catch all the radio in a vector from javascript?

+2  A: 

Using same ID for more than one element on page is incorrect! use name attribute to group these buttons.

f0rza
+2  A: 

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

Judas Imam
A: 

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

learner