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

253
Views
why input value is an empty string in this form?

I know it should be simple but i still can't realize what is the problem. I've created the form with the Id that i use for the variables and then after the submit i want to see the value of the input but i get "".

<form action="signIn.html" method="get">
<input type="text" name="name" id="names" placeholder="Name">
<input type="email" name="email" id="email" placeholder="Email">
<input type="password" name="password" id="password" placeholder="Password">
<label for="terms">
<input type="checkbox" name="terms" id="terms" value="terms">I agree to the Terms and Privacy Policy
</label>
  <div class="button">
  <input class="btn signUp" type="submit" value="Sign Up">                            
  </div>
const formulario = document.querySelector("form");
const nombre = document.querySelector("#names").value;
const email = document.querySelector("#email").value;
const password = document.querySelector("#password").value;
let correctData = [];
let errors = [];


formulario.addEventListener("submit", (e) => {
    e.preventDefault()
     console.log(nombre)
    console.log(email)
    console.log(password)
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are retrieving the values of the inputs on page load (which is a blank string, because initially the input has no value).

Instead, get the value inside the submit event handler.

const formulario = document.querySelector("form");
const nombre = document.querySelector("#names");
const email = document.querySelector("#email");
const password = document.querySelector("#password");
let correctData = [];
let errors = [];


formulario.addEventListener("submit", (e) => {
  e.preventDefault()
  console.log(nombre.value)
  console.log(email.value)
  console.log(password.value)
});
<form action="signIn.html" method="get">
  <input type="text" name="name" id="names" placeholder="Name">
  <input type="email" name="email" id="email" placeholder="Email">
  <input type="password" name="password" id="password" placeholder="Password">
  <label for="terms">
<input type="checkbox" name="terms" id="terms" value="terms">I agree to the Terms and Privacy Policy
</label>
  <div class="button">
    <input class="btn signUp" type="submit" value="Sign Up">
  </div>

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!