How do I unmark the previous radio button after selecting another?

3

I have five radio button , of these five one is "marked", how do I uncheck the radio button that I clicked after clicking another?

Example:

<fieldset>
  <legend>Selecione:</legend>
  <label>Morango:
   <input type="radio" id="A" checked/>
  </label>
  <label>Maracujá: 
   <input type="radio" id="B" />
  </label>
  <label>Melancia:
   <input type="radio" id="C" />
  </label>
  <label>Melão: 
    <input type="radio" id="D" />
  </label>
  <label>Mamão:
    <input type="radio" id="E" />
  </label>
</fieldset>
    
asked by anonymous 06.03.2017 / 21:15

1 answer

4

If you set the content of the name attribute to the inputs identically. Ex: name="myGroup" , by default you will have the desired behavior.

Follow below

<fieldset>
  <legend>Selecione:</legend>
  <label>Morango:
   <input type="radio" id="A" name="myGroup"/>
  </label>
  <label>Maracujá: 
   <input type="radio" id="B" name="myGroup" />
  </label>
  <label>Melancia:
   <input type="radio" id="C" name="myGroup" />
  </label>
  <label>Melão: 
    <input type="radio" id="D" name="myGroup" />
  </label>
  <label>Mamão:
    <input type="radio" id="E" name="myGroup" />
  </label>
</fieldset>
    
06.03.2017 / 21:19