felicia00
1 month ago

How to check if checkbox is checked?

Posted 1 month ago by felicia00

Is it the correct way to check if the check box is tick?

        <input type="checkbox" class="custom-control-input check" name="A" id="A" value= "<?php if(isset($resDtl[0]) && $resDtl[0]->A==1) echo "checked"; ?>" />
        <label class="custom-control-label" for="A">A</label>

JavaScript

var obj={};

      $(".check").each(function(){
            var name = this.name;
            if ($("[name='" + name + "']:checked").val() == true)
                obj[name] = true;
            else
                obj[name] = "";
        })

        return obj;

Please sign in or create an account to participate in this conversation.