Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Check if any form inputs are empty in Jquery
         $('#formRegisterUser').submit(function(){
      
            let inpUsername = $('input[name="username"]').val();
            let inpEmail = $('input[name="email"]').val();
            let inpPassword = $('input[name="password"]').val();
            let inpConfirmPassword = $('input[name="confirmPassword"]').val();
    
            if(inpUsername == '' || inpEmail == '' || inputPassword == '' || inpConfirmPassword == ''){
              return false;
            } else {
              return true;
            }
         }

I want to check whether if any of form input is empty return false else return true.But this way is kinda repititive.Is there any easy way? with just less code to do the same code with Jquery.Thanks

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Just make a jquery prototype function, same syntax below.

jQuery.prototype.isEmpty = function(){
    return this.context.value == '';
}

let isEmpty = $('input[name="username"]').isEmpty();

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!