JSFiddle - React, Tailwind, and code Playground

by Tan

HTML

<form onsubmit='return test();'>
category:
<input type="radio" name="categoryrate" value="5">
<input type="radio" name="categoryrate" value="4">
<input type="radio" name="categoryrate" value="3">
<input type="radio" name="categoryrate" value="2">
<input type="radio" name="categoryrate" value="1">
    <input type='submit' />
</form>

JavaScript

function test(){
  var category = document.getElementsByName("question");
  var check1 = 0;
  for(i=0;i<category.length;i++){
    if(category[i].checked){
      check1++;
      break;
    }
  }
  
  if(check1){
  }else{
    alert("Please select an answer");
    return false;
  }
}