Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether radio button is disabled or enabled [duplicate]

Tags:

<asp:RadioButtonList ID="rdStatus" onclick="javacript:display();" runat="server" RepeatDirection="Vertical">
<asp:ListItem Text="Temporary Waiver" Value="T" Selected="True"></asp:ListItem>    
<asp:ListItem Text="Never Expires" Value="P"></asp:ListItem>    
<asp:ListItem Text="Expires after the close of:" Value="W"></asp:ListItem>
</asp:RadioButtonList>

function display()
{
    if(radiobuton is enabled)
          //code here
     else
          //code here
}

Please suggest some idea to detect hoe to check radiobutton is disable o enable

like image 832
Blossom Avatar asked Sep 24 '13 05:09

Blossom


People also ask

How do you check radio button is enabled or not?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.

How do you check whether a radio button is checked or not in jQuery?

We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.

Can radio buttons be disabled?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .


1 Answers

Use jQuery to attach to the click event of the radio button list and then use the jQuery :enabled selector, like this:

$('#rdStatus').click(function () {
    if($(this).is(':enabled')) { 
        // Do enabled radio button code here 
    }
    else {
        // Do disabled radio button code here
    }
});

Now you can remove the onclick attribute of your radio button list markup, because jQuery is going to find the radio button list (rdStatus) and wire up the click event to it for you.

<asp:RadioButtonList ID="rdStatus" runat="server" RepeatDirection="Vertical">
like image 176
Karl Anderson Avatar answered Sep 20 '22 02:09

Karl Anderson