-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; } 
6
  • 1
    Can you paste your ASP.net html code Commented Dec 19, 2014 at 13:15
  • Please add your HTML code to your question Commented Dec 19, 2014 at 13:16
  • 1
    Where is this code block? is it in the head or in the body? Commented Dec 19, 2014 at 13:16
  • Its under <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <title>Test Page/title> Commented Dec 19, 2014 at 13:19
  • And on button click OnClientClick="return ValidateRadioButton();" Commented Dec 19, 2014 at 13:20

1 Answer 1

0

You should get your Radio button through ID

IF(document.getElementById("optfirst").checked) { //Code To Execute } 
Sign up to request clarification or add additional context in comments.

1 Comment

If the radio and the form have name attributes, how he is doing it is fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.