Home > Enterprise >  same id given to various btns
same id given to various btns

Time:04-10

I recently visited a website and was checking through its html code and found that two different inputs of type radio were given same id, how can it be possible? I tried to check the radio buttons but I was only able to check the first button how do I check the other buttons using javascript if both are given same id image radio buttons on the website

image of html code where same id given

CodePudding user response:

From MDN

elements of type radio are generally used in radio groups—collections of radio buttons describing a set of related options.

Only one radio button in a given group can be selected at the same time. Radio buttons are typically rendered as small circles, which are filled or highlighted when selected.

Every element on your document is expected to have a unique id value for its id property otherwise odd things would happen when trying to select those elements using a css selector both in styles and js (to cite one).

Here there's an in depth discussion on SO for example for further reference.

But for sure they are meant to be grouped using the same name attribute value to hint which group is expected to have a mutually exclusive checked status and to converge to the same GET/POST parameter, named like that name property and having as value the value of the only radio selected in its group, when its form will be submitted.

CodePudding user response:

What about if you try to get all the input fields with name and then try to select specific one with the index?

  • Related