Visual Studio .NET - how to validate radiobuttonlist using javascript

Asked By rafeeq ahmed on 06-Jun-06 10:16 AM

i have a radio button list,for gender,i have to validate that using javascript on client side Please any code how to do it .


thanks in advanced

function checkradio(form)
				if (count<1)
				alert('select gender');
				return false;

RequiredFieldValidator - Asked By F Cali on 06-Jun-06 10:30 AM

Instead of doing the validation yourself, I suggest using a RequiredFieldValidator for your RadioButtonList.
Asked By Sushila Patel on 06-Jun-06 11:58 AM
You can use Requiredfieldvalidator or else the javascript is as follows
function validateRadiobuttonlist() 
	var count =0;
	var rb = document.forms[0].rbl; // rbl is the RadioButtonList control  ID 
	for (var i=0; i< rb.length; i++) 
		if ( rb[i].checked )
			count = 1;
    if ( count<1 || count==0 )
		alert("Select Gender");
		return false;
    else alert ("Proceed."); 

Require a Dynamic function - Asked By rafeeq ahmed on 06-Jun-06 01:17 PM

i want a dynamic function i.e i send the name of the radiobutton list.and it do validation;
in my form there are many radiobuttonlist 

otherwise i have to write for each radiobuttonlist coding
Are you unable to take the sample code given - Asked By Robbe Morris on 06-Jun-06 01:19 PM
and modify it to include a parameter to be passed in?
getElement by id is notworking - Asked By rafeeq ahmed on 06-Jun-06 01:45 PM

i am passing the radiobuttonlist name but for checking any button is checked of not ,i m not getting the length throug
var rdlength=document.getElementbyId(pararadioname).length
and also unable to check any checkbox is checked

i m using
I want to validate using javascript only - Asked By rafeeq ahmed on 08-Jun-06 01:08 PM

i have many radiobutton list , and i have to validate them using only javascript,
i want a dynmic function using that i can validate any radiobuttonlist,just passing the name and number of radio buttons in a list.

thanks in advanced
shekhar kumar replied to rafeeq ahmed on 01-Nov-10 06:20 AM
I too had a problem similar to above .
I have tried the following code the radio button list is rendered in htm table tr and td tag
so you will have to code like this

function CountRadionCheck(radio1) {
            var TotalCount = 0;
            var tbl = document.getElementById(radio1);
            for (var count = 0; count < tbl.rows.length; count++) {

                if (tbl.rows[count].cells[0].getElementsByTagName('input').length > 0) {
                    var rbn = tbl.rows[count].cells[0].getElementsByTagName('input')[0];
                    if (rbn != null) {
                        if (rbn.checked == true) {
            return TotalCount

the above function returns no of counts of a radionbutton list.
Venkatesh replied to rafeeq ahmed on 04-Feb-11 06:09 AM

I would recommend you to use the following way to address this issue.

var radioButtons = document.getElementById('<%= RadioButtonList.ClientID %>');

     for (var x = 0; x < radioButtons.all.length; x++) {
       if (radioButtons.all[x].checked) {
        var strSelValue = radioButtons.all[x].value;