| Viewed 103 times

how to use radio button in html


how to use radio button in html

1 Answer
Mikdam Qandeel
Answered
7

A radio button in HTML is used to able the user to select one choice of some choices.

We write and define it like this <input type="radio"> .

Example:

<form>
       <p>Where are you from:</p>
       <input type="radio" name="city" value="jordan"> Jordan
       <br>
       <input type="radio" name="city" value="palestine"> Palestine
       <br>
       <input type="radio" name="city" value="uk"> UK
       <br>
       <input type="radio" name="city" value="other"> Other
</form>

Output:

Where are you from:

Jordan
Palestine
UK
Other


So, each <input> has the same name attribute is a group. and the value attribute is related to the value for the input, we have select it.

Example:

<form>
       <p>Where are you from:</p>
       <input type="radio" name="city" value="jordan"> Jordan
       <br>
       <input type="radio" name="city" value="palestine"> Palestine
       <br>
       <input type="radio" name="city" value="uk"> UK
       <br>
       <input type="radio" name="city" value="other"> Other

       <br>  

       <p>Your gender:</p>
       <input type="radio" name="gender" value="male"> Male
       <br>
       <input type="radio" name="gender" value="female"> Female
</form>

Output:

Where are you from:

Jordan
Palestine
UK
Other

Your gender:

Male
Female