Hide or Show div via a Radiobutton via Jquery

Asked

Viewed 1,914 times

1

Follow the code below:

HTML:

<asp:RadioButtonList ClientIDMode="Static" ID="rbAtivoInativo" runat="server" RepeatDirection="Horizontal" AutoPostBack="true"> <%--OnSelectedIndexChanged="rbAtivoInativo_SelectedIndexChanged"--%>
     <asp:ListItem Value="ATIVO" Selected="True">Sim</asp:ListItem>
     <asp:ListItem Value="INATIVO">Não</asp:ListItem>
</asp:RadioButtonList>

I wanted that when the Radiobutton with the INACTIVE value was selected a div appears that is hidden.

2 answers

0


Thank you very much for the reply, but I have already solved it. Follow the code in case someone ever needs it.

 $("#rbAtivoInativo input").click(function () {
    var select = $(this).val();
    if (select == "INATIVO") {
        $("#cphConteudo_divMotivoInativacao").show();
    } else {
        $('#cphConteudo_divMotivoInativacao').hide();
    }
});

0

Via jQuery?

Solution

First import jQuery, putting it into head file. After, create a div and define it initially as display: none; in style sheet. After, add interactivity (within a <script>): when clicked such, visible. If tal2, invisible. Example:

$('input#ativo').change(function(){
    $('div#alvo').fadeIn();
});

$('input#inativo').change(function(){
    $('div#alvo').fadeOut();
});

fadeIn and fadeOut can be quietly replaced by show and hide.

I created a Jsfiddle

I’m sorry if it wasn’t the request. I don’t know the Asp, however PHP and jQuery.

  • 1

    Just change in your 'active input#' and 'inactive input#' answer to 'input#rbAtivoInactive'. The rest is right.

  • Wasn’t this my placement.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.