0

I have an onChange event for a checkbox which fires a function that toggles the Visibility of some TRs. My problem is this code only works in firefox. I want it to work for ie8.

function toggleVisibility() {

    if ($("#ctl00_PageContent_chkVisibility").is(':checked')) {
        $('#ctl00_PageContent_freight_rate_column_chaair tr').each(function(i, val) { // Loop through rows in grid
            if (i > 9 & i < 28) {
                $('#ctl00_PageContent_freight_rate_column_chaair_r' + i).hide();
            };
        });
    }
    else {
        $('#ctl00_PageContent_freight_rate_column_chaair tr').each(function(i, val) { // Loop through rows in grid
            if (i > 9 & i < 28) {
                $('#ctl00_PageContent_freight_rate_column_chaair_r' + i).show();
            };
        });
    };
};

Does anyone know a better way of doing this?

Thanks

2 Answers 2

1

I would try using the "starts with" selector instead of trying to concat the id to the index number. Try something like this:

$('#ctl00_PageContent_chkVisibility').change(function () { 
    toggleVisibility()
});

function toggleVisibility() {
    if ($("#ctl00_PageContent_chkVisibility").is(':checked')) {
        $('#ctl00_PageContent_freight_rate_column_chaair tr').each(function (i, val) { // Loop through rows in grid
            if (i > 9 & i < 28) {
                $('input[id^="ctl00_PageContent_freight_rate_column_chaair_r"]').hide();
            };
        });
    }
    else {
        $('#ctl00_PageContent_freight_rate_column_chaair tr').each(function (i, val) { // Loop through rows in grid
            if (i > 9 & i < 28) {
                $('input[id^="ctl00_PageContent_freight_rate_column_chaair_r"]').show();
            };
        });
    };
};

You shouldn't need to concat the id to the index number because during the loop, you only need to check the index. At that index the hide function will hide the row at said index and thus there is no need to specify the exact id of the row you wish to hide.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks this helped me. Within my if condition I used my original jquery selector because it was hiding my user controls instead of hiding the correct rows based on ID. Thanks.
0

I guess you've declared something like this on your aspx page :

<asp:CheckBox ID="chkId" runat="server" onchange="toggleVisibility()"/>

This works on FF but not in IE.

Remove the onchange attribute on the checkbox element and also remove the function toggleVisibility and try to register your function with jquery using :

<script language="javascript">
$(function () {

$('#ctl00_PageContent_chkVisibility').change(function () {             
       // 
       // paste here your existing code , the body of the function toggleVisibility
});
});
</script>

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.