This topic contains 5 replies, has 3 voices, and was last updated by Sean Sean 2 years ago.

Material design checkbox


  • Albert
    Participant

    Member Reply #8696

    Hi,

    i use material design checkboxes in my forms. I need change the state with javascript or  jquery but it component not work like standar checkbox html control.

    How i can check or uncheck a checkbox?

    How i can know the state of checkbox?

    i try this, but, it not work:

    $(‘#mailing tbody input[type=”checkbox”]’).each(function(tnIndex, toElement) {

    // Force checked true

    $(toElement).attr(‘checked’, true);

     

    // Force checked false

    $(toElement).attr(‘checked’, false);

     

    // Know state

    $(toElement).attr(‘checked’);

    }

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #8718

    Hi,

    Please make sure that name attribute is properly set for each checkbox and try to use below jquery code:

    $(‘#my_checkbox’).attr(‘checked’, ‘checked’);

    The above code was tested and should work for your case as well. Just make sure you are referring to the valid jquery input(checkbox) and use ‘checked’ value to set the checked stated.

    Thanks.


    CAna
    Participant

    Posts: 16
    Member Reply #10060

    Sorry to open an old thread but I am having the same issue.

    This seems to work, it correctly unchecks the checkbox:

    $(‘#my_checkbox’).attr(‘checked’, false);

    But programatically checking it does not work. I have tried the following:

    $(‘#my_checkbox’).attr(‘checked’, true);

    $(‘#my_checkbox’).attr(‘checked’, ‘checked’);

    $(‘#my_checkbox’).attr(‘checked’, 1);

     

    Neither seems to work. I have tested the above on the Metronic page to make certain about latest version.

    Thanks.

     

    • This reply was modified 2 years ago by  CAna.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #10071

    Hi,

    Please try jquery’s prop method and let us know the result:

    $(‘#my_checkbox’).prop(‘checked’, true);

    Thanks.


    CAna
    Participant

    Posts: 16
    Member Reply #10074

    This works perftectly, thanks!

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #10081

    Great! Good luck with your project 🙂

You must be logged in to reply to this topic.