Skip to main content
added 1186 characters in body
Source Link
Sebastián Palma
  • 33.6k
  • 6
  • 45
  • 65

With jQuery you can use is:

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="hi">Hallo<br> <input type="checkbox" name="gb" value="gb">Tschuss<br> <input type="submit" value="Submit"> </form>

Adapted to your code:

$('.btnNext').click(function(e) { e.preventDefault(); if ($('#usp-category-7').is(':checked') || $('#usp-category-8').is(':checked')) { console.log('at least one is checked'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group"> <label for="usp-category-8" class="usp-checkbox usp-cat usp-cat-0"> <input type="checkbox" name="usp-category[]" id="usp-category-8" value="8" data-required="true" class="usp-input usp-input-category"> Cultura </label> <label for="usp-category-7" class="usp-checkbox usp-cat usp-cat-0"> <input type="checkbox" name="usp-category[]" id="usp-category-7" value="7" data-required="true" class="usp-input usp-input-category"> Scienze </label> <input type="hidden" name="usp-category-required" value="1"> <button class="btnNext">Next</button> </div>

With jQuery you can use is:

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="hi">Hallo<br> <input type="checkbox" name="gb" value="gb">Tschuss<br> <input type="submit" value="Submit"> </form>

With jQuery you can use is:

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="hi">Hallo<br> <input type="checkbox" name="gb" value="gb">Tschuss<br> <input type="submit" value="Submit"> </form>

Adapted to your code:

$('.btnNext').click(function(e) { e.preventDefault(); if ($('#usp-category-7').is(':checked') || $('#usp-category-8').is(':checked')) { console.log('at least one is checked'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group"> <label for="usp-category-8" class="usp-checkbox usp-cat usp-cat-0"> <input type="checkbox" name="usp-category[]" id="usp-category-8" value="8" data-required="true" class="usp-input usp-input-category"> Cultura </label> <label for="usp-category-7" class="usp-checkbox usp-cat usp-cat-0"> <input type="checkbox" name="usp-category[]" id="usp-category-7" value="7" data-required="true" class="usp-input usp-input-category"> Scienze </label> <input type="hidden" name="usp-category-required" value="1"> <button class="btnNext">Next</button> </div>

added 43 characters in body
Source Link
Sebastián Palma
  • 33.6k
  • 6
  • 45
  • 65

With jQuery you can use is:

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="Bike">Hallo<br>value="hi">Hallo<br> <input type="checkbox" name="gb" value="Car" checked>Tschuss<br>value="gb">Tschuss<br> <input type="submit" value="Submit"> </form>

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="Bike">Hallo<br> <input type="checkbox" name="gb" value="Car" checked>Tschuss<br> <input type="submit" value="Submit"> </form>

With jQuery you can use is:

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="hi">Hallo<br> <input type="checkbox" name="gb" value="gb">Tschuss<br> <input type="submit" value="Submit"> </form>

Source Link
Sebastián Palma
  • 33.6k
  • 6
  • 45
  • 65

$('#form').on('submit', function(e) { e.preventDefault(); if ($('input[name="hi"]').is(':checked')) { console.log('checked'); } }); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="checkbox" name="hi" value="Bike">Hallo<br> <input type="checkbox" name="gb" value="Car" checked>Tschuss<br> <input type="submit" value="Submit"> </form>