how to make radio btton checked wth value in js code example

Example 1: javascript radio button value if checked

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

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

if($test="silver") {
        amount=50;
    }else if($test="gold") {
      amount=90;
    }else{
      amount=30;
    }

Example 2: javascript on click radio button get value

if (document.getElementById('r1').checked) {
  rate_value = document.getElementById('r1').value;
}

Tags:

Html Example