'When I click on a radio button the checked attribute doesn't change

So I have this bit of code and I want it to change its selected attribute when I click on the other radio button.

<fieldset>
  <legend class="h4">Formati:</legend>
  <label class="radio-inline">
    <input type="radio" name="version_printimi" value="A4">A4
  </label>
  <label class="radio-inline">
    <input type="radio" name="version_printimi" value="Skontrino" checked="checked">Skontrino
  </label>
</fieldset>

They are inside a form and visually the radiobuttons do get changed but I need the changed attribute to change as well.



Solution 1:[1]

you can use onchange event listener to both of the input tags to detect change, then call a function that adds an attribute to one of the radio inputs using setAttribute and remove an attribute from other radio using removeAttribute.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dhruv champaneri