Search code examples
javascriptasp.netdotnetnukeradiobuttonlist

Getting .ascx RadioButtonLists Selected Item Via JS


I'm trying to get the currently selected item within an asp:RadioButtonList through the java script on the page. I've looked up how to do this, but none of the ways suggested has worked. I'm coding for a dnn module. Here's what I have:

<script type="text/javascript">
function BeginDownload() {
    var radioObj = document.getElementsByName('<%= SliderStyles.ClientID %>');
    for (var i = 0; i < radioObj.length; ++i ) {
        if (radioObj[i].checked) {
            if (radioObj[i].value == "0") { __doPostBack("ImgDownload", $("#waterwheel-carousel-horizon").CurrentSelectedImg().toString()); }
            else if (radioObj[i].value == "1") { __doPostBack("ImgDownload", $("#slides").CurrentSelectedImg().toString()); }
        }
    }
}

<asp:Label runat="server" Text="Slider Style" Font-Bold="True" />
<asp:RadioButtonList ID="SliderStyles" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="SliderStyle_OnSelectedIndexChanged" AutoPostBack="True">
    <asp:ListItem Text="Default" Value="0" Selected="True"></asp:ListItem>
    <asp:ListItem Text="Slide Show" Value="1"></asp:ListItem>
</asp:RadioButtonList>

So far the value I get in my Javascript returns null each time.


Solution

  • Your for loop is incorrect change the "++i" to "i++" like this

    for (var i = 0; i < radioObj.length; i++ )