check if radio is checked

hi experts,

i have a question for you:

how can i check if one of the radio button that I have in the page is checked?

sth like:

if (radio is cheked) return true
else alert("no radio checked" return false
Who is Participating?
sajuksConnect With a Mentor Commented:
<script language="JavaScript">
function radio_button_checker()
var radio_choice = false;
for (counter = 0; counter < radio_form.radio_button.length; counter++)
if (radio_form.radio_button[counter].checked)
radio_choice = true;
if (!radio_choice)
alert("Please select a letter.")
return (false);
return (true);


<form method="get" action=""
onsubmit="return radio_button_checker()" name="radio_form">
<input type="radio" value="A" name="radio_button">A
<input type="radio" value="B" name="radio_button">B
<input type="radio" value="C" name="radio_button">C
<input type="radio" value="D" name="radio_button">D
<input type="submit" value="Submit">

well this is more of a javascript question ... but theres a couple way's to do it ...

but if you make a function you could do this

function IsRadioButtonChecked( )
           alert( document.formname.radiobuttoname.checked );

            return document.formname.radiobuttonname.checked;

or you could pass the function the radio button you want to use

function IsRadioButtonChecked( objRadioButton )
           alert( objRadioButton.checked )
           return objRadioButton.checked;

so you could do this

<input type="button" name="btnTest" value="Click Me To See If A Radio Button Is Checked" onclick="IsRadioButtonChecked( );">


<input type="button" name="btnTest" value="Click Me To See If A Radio Button Is Checked" onclick="IsRadioButtonChecked( document.formname.radiobuttonname );">
And if you do want to do it in an asp page after submit then it returns it's value if checked, check it like this:

If Request.Form("radiobuttonName") <> "" Then
End If

Be sure the name and value are set or else it still won't work.
You can also have more radiobuttons with the same name, the checked one gives his value then. For example both names are name="gender" and the value of each is: value="Male" and value="Female"
Then you can see with Request.Form("gender") what value is chosen..
campanalAuthor Commented:
great  sajuks you are the best!!
Glad to help you out. Thanks for the points and grade.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.