&& operator is not working

TerryC03
Tera Guru

Hello,

 

May someone assist me in troubleshooting my code? I trying to prevent a user from submitting a form if a specific checkbox is not true (checked) as well as if there are no attachments on the form. However, the AND operator is not working as expected.

 

 

 

var checkbox = g_form.getValue('test');  
var countRequired = 0;
        if (window == null) {

            // portal
            if ( (this.document.getElementsByClassName('get-attachment').length == countRequired) &&
				(checkbox == true) ) {
                g_form.addErrorMessage('Please add the required attachments.');
                return false;
            } else {
                // native view
                var length = $j("li.attachment_list_items").find("span").length;
                if ( (length == countRequired) && (checkbox == true) ) {
                    g_form.addErrorMessage('Please add the required attachments.');
                    return false;
                }
            }
        }

 

 

With this code, the submission goes through with a javascript error.

 

Thanks