-1

I want to just check whether a radio button is selected or not through javascript. I am getting an object is undefined error with the below code.

function ValidateRadioButton() {
  if (document.form1.optfirst.checked == true)
  {
    alert("Option1 is checked");
  } else if (document.form1.optsecond.checked == true) {
    alert("Option2 is checked");
  }
  return false;
}
Sam Greenhalgh
  • 5,764
  • 19
  • 36
user3074125
  • 91
  • 1
  • 9

1 Answers1

0

You should get your Radio button through ID

IF(document.getElementById("optfirst").checked)
{
  //Code To Execute
}
Kaushal Khamar
  • 2,067
  • 1
  • 16
  • 23