Search code examples
htmlbootstrap-4

Bootstrap multipile checkbox with same id unclickable


I have checkbox like this

<div class="form-group">
                    <div class="col-sm-3">
                        <div class="checkbox clip-check check-primary">
                            <input type="checkbox" value="machine" name="type[]" id="type">
                            <label for="machine">
                                Mesin
                            </label>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="checkbox clip-check check-primary">
                            <input type="checkbox" value="utility" name="type[]" id="type">
                            <label for="utility">
                                Utility
                            </label>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="checkbox clip-check check-primary">
                            <input type="checkbox" value="others" name="type[]" id="type">
                            <label for="others">
                                Others
                            </label>
                        </div>
                    </div>
                </div>

My problem is i cant even check or uncheck my input. Is there i get worng with these code??

NOTE : I'm using same id because i need used to valided on jquery. If i'm using different id the validate did not working at all.


Solution

  • Modify the HTML in this manner:

    <div class="form-group">
      <div class="col-sm-3">
        <div class="checkbox clip-check check-primary">
          <input type="checkbox" value="machine" name="type[]" id="machine">
          <label for="machine">
            Mesin
          </label>
        </div>
      </div>
      <div class="col-sm-3">
        <div class="checkbox clip-check check-primary">
          <input type="checkbox" value="utility" name="type[]" id="utility">
          <label for="utility">
            Utility
          </label>
        </div>
      </div>
      <div class="col-sm-3">
        <div class="checkbox clip-check check-primary">
          <input type="checkbox" value="others" name="type[]" id="others">
          <label for="others">
            Others
          </label>
        </div>
      </div>
    </div>
    

    Keep the same value of ID which is present in the for attribute of label