Answers for "multiple checkbox checked value in jquery"

2

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
0

multiple checkbox validation in jquery

function onSubmit() 
{ 
    var fields = $("input[name='list']").serializeArray(); 
    if (fields.length === 0) 
    { 
        alert('nothing selected'); 
        // cancel submit
        return false;
    } 
    else 
    { 
        alert(fields.length + " items selected"); 
    }
}

// register event on form, not submit button
$('#subscribeForm').submit(onSubmit)

//**************************************************
// HTML
<form method="POST" id="subscribeForm">
    <fieldset id="cbgroup">
        <div><input name="list" id="list0" type="checkbox"  value="newsletter0" >zero</div>
        <div><input name="list" id="list1" type="checkbox"  value="newsletter1" >one</div>
        <div><input name="list" id="list2" type="checkbox"  value="newsletter2" >two</div>
    </fieldset>
    <input name="submit" type="submit"  value="submit">
</form>
Posted by: Guest on July-02-2021
-1

get multiple checkbox value in jquery

//get multiple checkbox value in jquery

$(document).ready(function(){
$(".chk").click(function(){
var d = $("input[name=test]"); if(d.is(":checked")){
//
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="test"> `test1`
<input type="checkbox" name="test"> `test2`
<input type="checkbox" name="test"> `test3`
<input type="button" value="check" class='chk'/>
Posted by: Guest on July-09-2021

Code answers related to "multiple checkbox checked value in jquery"

Browse Popular Code Answers by Language