function checkForm(){ if (grecaptcha.getResponse() == ""){ var box = bootbox.alert("Please confirm you're not a robot"); box.find('.btn-primary').css({'font-size': '16px','height' :'40px', 'padding-top':'8px'}); box.find('.modal-content').css({'margin-top': '90px'}); flag = false; } var form = document.getElementsByName("qform"); var inputs1 = document.getElementsByTagName("input"); var input = null; var flag = true; var alert=""; var agree = document.getElementById("quote-agree"); var first_fail = 25; for(var i = 0, len = inputs1.length; i < len-1; i++) { input = inputs1[i]; if (!(input.id == "quote-instr" || input.id == "quote-date" || input.id == "quote-account" || input.id == "quote-bill" )){ if(!input.value) { flag = false; input.focus(); alert ="Please fill all the inputs\n"; first_fail = Math.min(i,first_fail); } } } inputs1[first_fail].focus(); if( agree.checked == false){ flag = false; alert +="Please agree terms and conditions";} console.log(alert); return flag; }