Is there a .change event for checkboxlist?

(3 posts) (2 voices)
  1. cris, Member

    I have a checkbox list as a connected parameter. I want to color red some of the checkbox labels if the word 'Caution' appears in the label text. I can do this:


    if ($('label[for="addNewRecord_u9_1_cbl"]').is(':contains("Caution")')) {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'red');
    }
    else {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'green');
    }

    However, this only works for the initial loading of the checkbox list. If previous selections change the content of the checkbox list, the color does not change. I tried using the .change event for the checkbox list, but it doesn't seem to work?


    $('#addNewRecord_u9_1_cbl').change(function(){ if ($('label[for="addNewRecord_u9_1_cbl"]').is(':contains("Caution")')) {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'red');
    }
    else {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'green');
    } });

    I also tried just $('#addNewRecord_u9').change with no effect. Am I putting the .change on the wrong selector?

    Thanks,
    Cris

    Posted 3 months ago #
  2. myDBR Team, Key Master

    Cris,
    the change event will not work as the whole parameter is refetched via Ajax when the change on parent parameters happen.

    What you can do is to update to the latest version which allows use of dbr.html with connected parameter labels. You can use:

    select id, concat( 'dbr.html:<span style="color:', if (label like '%Caution%', 'red', 'green')  ,'">', label, '</span>')
    from param
    where ...

    When using this, there is no need for JavaScript and both initial load and subsequent Ajax loads work alike.

    --
    myDBR Team

    Posted 3 months ago #
  3. cris, Member

    Awesome. Works perfectly. Thank you.

    Posted 3 months ago #

Reply

You must log in to post.