0

I have a form which is outputting a number of checkbox.

The form is working well when I have atleast 1 checkbox check.

I would like to show an alert message is no checkbox are check when a user is clicking on submit. How can I accomplish this?

<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>
anatp_123
  • 1,165
  • 2
  • 10
  • 25
  • 1
    [What have you tried](http://mattgemmell.com/what-have-you-tried/)? Also, did you search the archives first? [This is a very common question](http://stackoverflow.com/questions/11787665/making-sure-at-least-one-checkbox-is-checked). – Leigh Jun 06 '15 at 00:22
  • 1
    What's this got to do with ColdFusion? It's an HTML/JS question. – Adam Cameron Jun 06 '15 at 06:36

1 Answers1

0

Assuming you're using jQuery, you can do the following:

// 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();

    }

} );
cfahey
  • 16