Submit form only if at least one checkbox is checked

后端 未结 8 2082
梦如初夏
梦如初夏 2021-01-06 18:42

i\'m triyng to validate a form. In this form you\'ve to choose at least one element by checkboxes, and I can\'t be sure about their quantity (it depends by elements number).

8条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 19:12

    //dom ready handler
    jQuery(function ($) {
        //form submit handler
        $('#booking').submit(function (e) {
            //check atleat 1 checkbox is checked
            if (!$('.roomselect').is(':checked')) {
                //prevent the default form submit if it is not checked
                e.preventDefault();
            }
        })
    })
    

提交回复
热议问题