Answers for "multiple checkbox selection in html jquery"

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
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

Code answers related to "multiple checkbox selection in html jquery"

Browse Popular Code Answers by Language