How can I write Javascript or JQuery to hide all the not checked elements from RadioButtonList?

Viewed 72

I am using Asp .net repeater and binding the selected value in the RadioButton list.

For example -

<asp:RadioButtonList ID="RadioButtonList1" runat="server" SelectedValue='<%# Eval("Numbers") %>'>
                <asp:ListItem Value=“1” Text=“First”></asp:ListItem>
                <asp:ListItem Value=“2” Text=“Second” ></asp:ListItem>
                <asp:ListItem Value=“3” Text=“Third” ></asp:ListItem>
            </asp:RadioButtonList>

So, I am getting the selected item when page loads but I want to hide other items which are no selected from that list when page loads.

1 Answers

This script will hide all of your remaining radio inputs after you click one of the radio.

let radios = document.querySelector('input[type="radio"]');
        for (let i = 0; i < radios.length; i++) {
            radios[i].onclick = function () {
                for (let j = 0; j < radios.length; j++) {
                    if (radios[j] != this) {
                        radios[j].style.display = 'none'
                    }
                }
                }
            }
Related