html radio value code example

Example 1: get radio button value javascript

document.querySelector('input[name="rate"]:checked').value;

Example 2: html radio button checked

<input type="radio" id="huey" name="drone" value="huey"
         checked> 
<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio-->

Example 3: html radio only one checked

<!--Just manke both names equal -->
<input type="radio" name="options" id="1"/>
<input type="radio" name="options" id="2"/>

Example 4: input radio html

<form>
  <p>Veuillez choisir la meilleure méthode pour vous contacter :</p>
  <div>
    <input type="radio" id="contactChoice1"
     name="contact" value="email">
    <label for="contactChoice1">Email</label>

    <input type="radio" id="contactChoice2"
     name="contact" value="telephone">
    <label for="contactChoice2">Téléphone</label>

    <input type="radio" id="contactChoice3"
     name="contact" value="courrier">
    <label for="contactChoice3">Courrier</label>
  </div>
  <div>
    <button type="submit">Envoyer</button>
  </div>
</form>

Example 5: radio input value

<input type="radio" name="test" id="test" value="this is the value">

Tags:

Php Example