【问题标题】:How to check at least 1 check box is check before submitting form? [duplicate]如何在提交表单之前选中至少 1 个复选框? [复制]
【发布时间】:2023-03-20 10:10:01
【问题描述】:

我有一个输出多个复选框的表单。

当我选中至少 1 个复选框时,表单运行良好。

我想显示一条警告消息,未选中复选框 当用户点击提交时。 我怎样才能做到这一点?

<form method="post" action="delete.cfm"  id="confrm_key">   
  <table >                                                                                    
        <cfoutput query="query">   
        <td> <input  name="check_delete"  type="checkbox" class="checking_id"   value="#id_table#" ></td>  
        <td><input type="hidden" name="time_Id" class="timebox" id="name_id2" value="#time_amount#">   </td>
         </cfoutput> 
        </table>

         <p><input type="submit"  name="Submit" value="Delete"   ></p> 

 </form>

【问题讨论】:

标签: coldfusion


【解决方案1】:

假设您使用的是 jQuery,您可以执行以下操作:

// when the form submit event occurs
$("#confrm_key").submit( function( event ) {

    // if we don't have any checked checkboxes
    if ( $(this).find(":checked").length === 0 ) {

        // throw an alert
        alert( "Warning message here." );

        // and stop the submission event
        event.preventDefault();

    }

} );

【讨论】:

    猜你喜欢
    • 2014-04-09
    • 2014-04-28
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 2018-07-29
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多