Latest

random

Get Value of Selected Radio Button JavaScript

Accessing radio button value in javascript

In this blog post, I will demonstrate how to get the checked value of radio button in javascript. Find the javascript code snippet below :- 
form radio button,  html5 radio button,  radio button onclick, html radio checked, radio buttons html,
getting values from radio button in html - asp.net
Default.aspx
<%@ 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>html radio button selected value javascript</title>

    <script type="text/javascript">
    function getSelectedRadioButtonValue() {
            var ctr = 0;
            var radiodbtn=document.getElementsByName("radiodbtn");
            var radioLength = radiodbtn.length;
            for (var i = 0; i < radioLength; i++) {
                if (radiodbtn[i].checked) {
                    alert(radiodbtn[i].value);
                    break;
                }
                ctr++;
            }
            if (ctr == radioLength)
                alert("None of the category has been selected:");
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div style="border: 10px; border-color: Gray;">
        <table cellspacing="15">
            <tr>
                <td valign="top">
                    <asp:Label ID="Label1" runat="server" Text="Select Category"></asp:Label>
                </td>
                <td>
                    <input type="radio" value="ASP.Net" name="radiodbtn" />ASP.Net
                    <input type="radio" value="C#" name="radiodbtn" />C#
                    <input type="radio" value="Google Maps" name="radiodbtn" />Google Maps
                    <input type="radio" value="MVC4" name="radiodbtn" />MVC4
                    <input type="radio" value="Entity Framework" name="radiodbtn" />Entity Framework
                </td>
                <td>
                    <input type="button" value="Get Value" onclick="getSelectedRadioButtonValue()" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

No comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.