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

214
Views
Why is the value of my password field always an empty string?

I've been working on my javascript skills lately and the password validation has given me a lot of trouble. The last thing that is stopping me is that the password field always has a value of an empty string for some reason.

It always logs out an empty string, no matter what i put in the input field. I've tried a different browser but that did not have an effect.

<input type="password" id="password">
<button type="submit" onclick="submitIt()">
Submit
</button>

js

const passWord = document.getElementById('password').value

function submitIt() {
console.log(passWord)
}

Here is the jsfiddle: https://jsfiddle.net/k4owfLzn/3/

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your value is always empty because the value of passWord is set on the loading of page. It is not updated after a user types in a value.

If you modify the code so it is like this you should get the value.

function submitIt() {
  const passWord = document.getElementById('password').value;

  console.log('passWord: ', passWord)
}
about 4 years ago · Juan Pablo Isaza Report

0

const passWord

was declared outside the function. I am sure that if you insert it inside the function, you will have the result you were looking for. :)

about 4 years ago · Juan Pablo Isaza 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!