JSFiddle - React, Tailwind, and code Playground

by ninty9notout

HTML

<form class="form">
  <label>
    <input type="radio" class="input" name="radio" value="Manual Value"> Manual Value
  </label>
  
  <label>
    <input type="radio" class="input" name="radio"> Default Value
  </label>
  
  <input type="submit">
</form>

JavaScript

var inputs = document.querySelectorAll('.input');

var form = document.querySelector('.form');

form.addEventListener('submit', function (event) {
	event.preventDefault();

	[].forEach.call(inputs, function (item) {
    if ('type' in item && (item.type == 'checkbox' || item.type == 'radio') && item.checked) {
      alert(item.value);
    }
  });
}, false);