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

Time:04-29

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 >Formati:</legend>
  <label >
    <input type="radio" name="version_printimi" value="A4">A4
  </label>
  <label >
    <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.

CodePudding user response:

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.

  • Related