User Id :    Password :      New Member   Forgot Password  
Validate radio button list in javascript in
Description This code snippet will check if any of the radio button in the radio button list is selected or not in javascript in   No. of Views     12100
  Rating     5
Author Najmul Hoda   Posted On     07 Sep 2011
Tags ASP.NET,Java Script    

Sample Code   Download Code


Here in this code snippet I will show how we can check if any of the radio button in the radio button list is selected or not before submitting the page in javascript in


function validateRadioButtonList(radioButtonListId) {
    var listItemArray = document.getElementsByName(radioButtonListId);
    var isItemChecked = false;

    for (var i = 0; i < listItemArray.length; i++) {
        var listItem = listItemArray[i];

        if (listItem.checked) {
            isItemChecked = true;

    if (isItemChecked == false) {
        alert('Please select a project!');

        return false;

    return true;


<asp:Button ID="btnSubmit" Text="Submit" runat="server" onclientclick=" return validateRadioButtonList('rdbProjectList');" OnClick="btnSubmit_Click" />


Here in the above code you can see when a user clicks on the submit button, client side code is executed first and checks if any of the item in the radio button list is selected. If any of the radio button is selected then page is submitted to server else user is prompt to select a radio button.

Hope this will help!!!!!!!!


About Author

About Author He is a team lead, having 8+ years of experience. He loves writing technical article for .Net developers. Najmul Hoda
No Photo
Country United States
Company BirlaSoft
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Write your comment here.
Verification Code