Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Add "Checked" in Input Attributes

Viewing 4 posts - 1 through 4 (of 4 total)
  • Zheng Liao
    #18566

    hello, is there a way to add “Checked” attributes to the Input when it is selected, and remove “Checked” when it is unselected?

    Thanks!

    Ross Moderator
    #18601

    Hi Zheng,

    I believe your browser already does this by default?

    Thanks

    Zheng Liao
    #19003

    hello Ross,

    just when I use firebug, I cannot see checked=”checked” within the <input> tag?

    I wrote a piece of JQuery code to change the default style as below, but it doesn’t add checked=”checked” to <input> and “checkedbox” class to <span> either as it is supposed to, do you have any idea why?

    my code:
    $(‘input:checkbox’).hide().each(function() {
    $(this).attr(‘data-check-fx’, this.value);
    var label = $(“label[for=” + ‘”‘ + this.id + ‘”‘ + “]”).text();
    $(‘‘+'<span class=”checkbox’ + (this.checked ? ‘ checkbox-checked’ : ”) + ‘”></span>‘).insertAfter(this);
    });

    $(‘sf-field-tag label’).on(‘click’, function(e) {
    e.preventDefault();
    if($(this).find(‘input:checkbox’).is(‘:checked’)) return;
    var unique = $(this).find(‘a.check-fx’).attr(‘data-check-fx’);
    $(“sf-field-tag label a[data-check-fx='”+unique+”‘] span”).attr(‘class’,’checkbox’);
    $(“sf-field-tag label input:checkbox[data-check-fx='”+unique+”‘]”).attr(‘checked’,false);
    $(this).find(‘a.check-fx’).find(‘span’).attr(‘class’,’checkbox-checked’);
    $(this).find(‘input:checkbox’).attr(‘checked’,true);
    }).on(‘keydown’, function(e) {
    if ((e.keyCode ? e.keyCode : e.which) == 32) {
    $(this).trigger(‘click’);
    }
    });

    Thanks!
    Emma

    Ross Moderator
    #19059

    Hi Emma

    I’m not sure what you are trying to achieve?

    If you take a look here:

    http://www.w3schools.com/html/tryit.asp?filename=tryhtml_checkbox

    And use firebug to inspect the checkbox, and then tick/untick the box, you won’t see a “checked” attribute being applied.

    If you are using jQuery I believe the correct way to detect if its checked is by using .prop("checked") instead of .attr("checked").

    Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.