Quiero hacer una funcion javascript que me retorne la cantidad de campos vacios en un form. Esto con el fin de obligar al usuario llenar al menos 3 campos para poder realizar una busqueda.
Hice lo siguiente pero no me funciona:
Código HTML:
function quantityOfEmpty(){ var account = document.frmSearch.Account.value; var first = document.frmSearch.FirstName.value; var last = document.frmSearch.LastName.value; var email = document.frmSearch.Email.value; var pass = document.frmSearch.Password.value; var web = document.frmSearch.cmbWebSite.value; var ip = document.frmSearch.IpAddress.value; var login1 = document.frmSearch.LoginDateIni.value; var login2 = document.frmSearch.LoginDateEnd.value; var zip = document.frmSearch.Zip.value; var phnumber = document.frmSearch.Phnumber.value; var active = document.frmSearch.optionsActive.value; var success = document.frmSearch.optionsSuccess.value; validate(account,first,last,email,pass,web,ip,login1,login2,zip,phnumber,active,success) if(validate < 3 ){ alert('Debes de llenar al menos 3 campos'); return false; }else return true; } function validate(account,first,last,email,pass,web,ip,login1,login2,zip,phnumber,active,success){ var count = 0; if(account.value != "") count = count + 1; if(first.value != "") count = count + 1; if(last.value != "") count = count + 1; if(email.value != "") count = count + 1; if(pass.value != "") count = count + 1; if(web.value == 0) count = count + 1; if(ip.value != "") count = count + 1; if(login1.value != "") count = count + 1; if(login2.value != "") count = count + 1; if(zip.value != "") count = count + 1; if(phnumber.value != "") count = count + 1; if(active.value != "") count = count + 1; if(success.value != "") count = count + 1; return count; }