Home > Software design >  How to select a single radio option?
How to select a single radio option?

Time:12-08

I can't select a single radio option. It's keeps selecting all radios

I created 4 radio option and I'm trying to select only 1 button, and it's keeps selecting all. I used pure html coding no JavaScript attached to it

CodePudding user response:

You're not naming them, name="Somename" is necessary to select only one option, input have to be named with same name.

Reference here.

<div>
  <h1>Named inputs</h1>
  <label><input type="radio" name="Somename"> Option1</label>
  <label><input type="radio" name="Somename"> Option2</label>
  <label><input type="radio" name="Somename"> Option3</label>
  <label><input type="radio" name="Somename"> Option4</label>


  <h1>Not named inputs</h1>
  <label><input type="radio"> Option1</label>
  <label><input type="radio"> Option2</label>
  <label><input type="radio"> Option3</label>
  <label><input type="radio"> Option4</label>
</div>

CodePudding user response:

Basically, the radio button on the html can only be selected only one, try to see documentation of html or w3school

  • Related