Click here to Skip to main content
13,299,298 members (61,694 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 1 Jul 2011

Show/Hide the Div with RadioButtonList Using JavaScript

, 1 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Making the div show/hide based on the selected radiobutton from the radiobuttonlist using JavaScript.


Here, I show a simple way of getting the selected/checked radiobuttonlist and show and hide a div using JavaScript.

The below page is the default.aspx which has the JavaScript method by name GetRDBValue and the parameters are sent by adding attribute onclick in the code behind (default.aspx.cs) i.e., page_load of the same.

Here, if the radiobutton yes is selected, I show the div and if no is selected, I hide the div. The rest of the code is self explanatory.


<%@ Page Language="C#" AutoEventWireup="true"  

CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 


<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>    
      <script type="text/javascript" language="javascript">
      function GetRDBValue(showw)
        var showdiv = document.getElementById(showw);
            var radio = document.getElementsByName('rdbGender');
             if(radio.length > 0)
	            for(var j=0 ; j < radio[0].cells.length ; j++)
		            for(var k=0 ; k < radio[0].cells[j].children.length ; k++)
			            if(radio[0].cells[j].children[k].checked == 
			            true && radio[0].cells[j].innerText == "Yes")
			     ="block" ;

			            else if(radio[0].cells[j].children[k].checked == 
			            true && radio[0].cells[j].innerText == "No")
			   = "none";

    <form id="form1" runat="server">
    <div id="checkdiv" runat="server" 

    style="display:none">Lokesh perumbali</div>
    <asp:Panel ID="pnl1" runat="server" 

    style="display:none">Lokesh test</asp:Panel>
    <asp:RadioButtonList ID="rdbGender" runat="server">
            <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
            <asp:ListItem Text="No" Value="2"></asp:ListItem>            



using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)
		string.Format("GetRDBValue('{0}');", checkdiv.ClientID));


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Wipro Technologies
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Generalshow hide div Pin
Java Experience24-Dec-12 5:13
memberJava Experience24-Dec-12 5:13 
GeneralMy vote of 5 Pin
Omar Gamil1-Jul-11 11:46
memberOmar Gamil1-Jul-11 11:46 
SuggestionNot really an article Pin
DaveAuld1-Jul-11 7:50
mentorDaveAuld1-Jul-11 7:50 
GeneralRe: Not really an article Pin
AspDotNetDev1-Jul-11 12:11
mvpAspDotNetDev1-Jul-11 12:11 
GeneralRe: Not really an article Pin
Richard MacCutchan1-Jul-11 22:51
mvpRichard MacCutchan1-Jul-11 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 1 Jul 2011
Article Copyright 2011 by lperumb
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid