JSFiddle - React, Tailwind, and code Playground

by Michel Plungjan

HTML

<div id= "genre">
  What do you bust a move to?
  <br>
  <br>
  <form name="music" method="post" action="">
  <input type="radio" name="music" id="bRad" value="b"><label for="bRad">Blues</label>
  <br>
  <input type="radio" name="music" id="rRad" value="r"><label for="rRad">Rock</label>
  <br>
  <input type="radio" name="music" id="pRad" value="p"><label for="pRad">Pop</label>
  <br>
  <br>
  </form>
</div>

JavaScript

var cols = {
  "r":"#FF0000",
  "b":"#0000FF",
  "p":"#FF00FF"
} // no comma after the last
window.onload=function() { // when the page loads
  var rads = document.getElementsByName("music"); // all rads named music
  for (var i=0;i<rads.length;i++) {
    rads[i].onclick=function() {
      var col = cols[this.value];
      document.body.style.backgroundColor=col;
    }
  }
}