ASP.Net: Call JavaScript function when RadioButton is checked or unchecked

Category > ASP.NET || Published on : Thursday, September 14, 2017 || Views: 9428 || ASP.Net Call JavaScript function RadioButton is checked or unchecked RadioButton


Introduction

Here Pawan Kumar will explain how to ASP.Net: Call JavaScript function when RadioButton is checked or unchecked

Description

In previous post I have explained MySQL Tutorial, Mvc 4 Razor CRUD Operation using C# || ASP.NET MVC 4 application to Create/Insert,Read,Update,Delete and Search functionality using Razor view engine and Entity Framework, Top Popular Open Source E-Commerce ASP.Net Projects, Calculator in Winform DotNet using C Sharp, Swapping of two numbers without using third variable using dotnet with c sharp, How to do Client Side OnCheckChanged event for ASP.Net CheckBox using JavaScript, and many more articles.

Now I will explain How to ASP.Net: Call JavaScript function when RadioButton is checked or unchecked

So follow the steps to learn ASP.Net: Call JavaScript function when RadioButton is checked or unchecked
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <script type="text/javascript">
        function ShowHideDiv() {
            var chkYes = document.getElementById("<%=chkYes.ClientID %>");
            var dvAadhaar = document.getElementById("dvAadhaar");
            dvAadhaar.style.display = chkYes.checked ? "block" : "none";
        }
    </script>
    <span>Do you have Aadhaar?</span>
    <asp:RadioButton ID="chkYes" GroupName="Aadhaar" Text="Yes" runat="server" onclick="ShowHideDiv()" />
    <asp:RadioButton ID="chkNo" GroupName="Aadhaar" Text="No" runat="server" onclick="ShowHideDiv()"  />
    <hr />
    <div id="dvAadhaar" style="display: none">
        Aadhaar Number:
        <input type="text" id="txtAadhaarNumber" />
    </div>
    </form>
</body>
</html>

 

Conclusion:

So, In this tutorial we have learned, ASP.Net: Call JavaScript function when RadioButton is checked or unchecked