Answers for "checkbox checked multiple"

3

multiple checkbox checked value in jquery

<!-- Find values of checked boxes with jquery -->
<div class="fruit">
  <label>
    <span>Apple</span>
    <input onchange="checkValues()" name="apple" type="checkbox" value="apple">
  </label>

  <label>
    <span>Banana</span>
    <input onchange="checkValues()" name="banana" type="checkbox" value="banana">
  </label>

  <label>
    <span>Grape</span>
    <input onchange="checkValues()" name="grape" type="checkbox" value="grape">
  </label>
</div>

<script>
  function checkValues() {
    $('.fruit input:checkbox').each(function(index, element) {
      if (element.checked === true) {
        console.log(element.value)
      }
    });
  }
</script>
Posted by: Guest on July-28-2021
1

get multiple checkbox value in javascript

<!DOCTYPE html>
<html>
    <body>
        <label>Check Which you have</label><br/>
        <input type="checkbox" id="checkbox1" name="bike" value="Bike"> Bike <br/>
        <input type="checkbox" id="checkbox2" name="car" value="Car"> Car   <br/>

 
        <input type="checkbox" id="checkbox3" name="home" value="Home"> Home <br/>
        <button onclick="getValue()">Get Value</button>
        <p id="p1"></p>
        <script>
            function getValue() {
             var ele=[]
              var bike = document.getElementById("checkbox1")
              if(bike.checked){
                    ele.push(bike.value);
             }
             var car = document.getElementById("checkbox2")
              if(car.checked){
                    ele.push(car.value);
             }
             var home = document.getElementById("checkbox3")
              if(home.checked){
                    ele.push(home.value);
             }
               if(ele.length>0){
                document.getElementById("p1").innerHTML = ele;
               }
               else{
               document.getElementById("p1").innerHTML = "You Dont have any thing";
               }
             }
             
             
        </script>
    </body>
</html>
Posted by: Guest on February-12-2021

Code answers related to "checkbox checked multiple"

Browse Popular Code Answers by Language