Search code examples
javascriptasp.netradiobuttonlist

Prevent calling javascript function on disable radiobuttonlist


Code

<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>

My Problem:

  • during run this code html table is created for radio button list and on click event is placed on table.
  • even i disable the radiobutton list , the click event is occur. I need to avoid this issue . Please suggest some ideas.

Solution

  • On disable radio buttons add class as "disabled" to radio buttons & better way to use jQuery insted of javascript as bellow

    jQuery("#rdStatus").click(function()`{  
    
        if(jQuery(this).hasClass("disabled"))
            return false;
    
        continue with you code here.............
    }`);