Skip to main content
February 5, 2014
Question

validate check box

  • February 5, 2014
  • 1 reply
  • 440 views

I have the type file for users to upload file.  If they browse the file, they have  to select the document type from the check box and versus.  This code didn't do what  I want.  Can onyone pls help?

Thanks

<script>

function validateForm(oForm) {

var numChecked = 0;

        for (var idx=0; idx<oForm.doc_type.length; idx++) {

                if (oForm.doc_type[idx].checked == true) {

                        numChecked++;

                        break;

                }

        }

if (document.getElementById ("cpc").value.length ! == 0)

           if (numChecked == 0){

                alert('Please check at least one checkbox');

                return false;

        }

                     return false;

}

          //all checked, then return true for submit

          return true;

} </script>

<form action="index.cfm?action=APrpocess" method="post"  enctype="multipart/form-data" name="form" id="form" onsubmit="return validateForm(this);">

<input name="cpc" class="upload" type="file" id="cpc" size="20" tabindex="8" />

          <cfloop query="variables.qDocType">

        <input  type="radio" id="doc_type" name="doc_type" size="20" tabindex="3"  value="#id_int#" <cfif id_int eq form.doc_type>checked="checked" </cfif> />#type_var#

     </cfloop>

</form>

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    February 5, 2014

    The form has a radio field instead of checkboxes.