-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,952
  • 21
  • 37
user3074125
  • 91
  • 2
  • 10

1 Answers1

0

You should get your Radio button through ID

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