User Id :    Password :      New Member   Forgot Password  
 
Validate radio button list in javascript in asp.net
Description This code snippet will check if any of the radio button in the radio button list is selected or not in javascript in asp.net   No. of Views     11293
  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 asp.net.

 

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) {
            //alert(listItem.value);
            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 http://www.magixchat.com

Rate this article

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

Comments

   
Write your comment here.
Comment
Verification Code