0

Ok I have checked several solution and have no luck. What the heck am I doing wrong. I can retrieve the ID from check_controls doing an alert onload but not on change

<asp:CheckBox ID="chkAutoReverse" runat="server" CssClass="" Width="200px" 
     Text="Auto Reverse:" TextAlign="Right" AutoPostBack="false" />

$(document).ready(function() {
    var check_controls = $('input[id*=chkAutoReverse]');
    var AutoReverseOptions = document.getElementById('AutoReverseOptions');

    $(check_controls).change(function() {
        if ($(this).is(':checked')) {
            alert($(check_controls).attr("id"));

        } else {
            alert($(AutoReverseOptions).attr("id"));
        }
    });
});

additional html markup

                            <div style="height: 60px">
                            <div class="singlepanelcontentleft">
                                <asp:CheckBox ID="chkAutoReverse" runat="server" CssClass="" Width="200px" Text="Auto Reverse:"
                                    TextAlign="Right" AutoPostBack="false" /></div>
                            <div id="AutoReverseOptions" class="singlepanelcontentleft" style="display: none;">
                                <asp:RadioButtonList ID="optTabs" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table"
                                    Width="91%" Height="22px">
                                    <asp:ListItem Text="Next Period" Value="1" Selected="true"></asp:ListItem>
                                    <asp:ListItem Text="2 Periods from Now" Value="2"></asp:ListItem>
                                    <asp:ListItem Text="3 Periods from Now" Value="3"></asp:ListItem>
                                </asp:RadioButtonList>
                            </div>
                        </div>

this is nested in other divs and a fieldset. Pasting the other code did not render well

2
  • I created a demo page with your code, it works fine for me. What does the rest of your markup look like? Commented Aug 26, 2011 at 1:36
  • @Rick, I updated the original post Commented Aug 26, 2011 at 1:53

4 Answers 4

1

you should reference asp.net IDs using the following:

<%= chkAutoReverse.ClientID %>
Sign up to request clarification or add additional context in comments.

Comments

0

Either reference the ClientID or set the ClientIDMode: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

Comments

0

Listening to checkboxes works better with a click event than a change event.


Attribute selectors need to be enclosed in quotes:

var check_controls = $('input[id*="chkAutoReverse"]');

Comments

0

OK I found the answer. You can get the details here. It boiled down the the controls being in an update panel and not resubscribing to the jQuery events when the panel loaded.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.