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

124
Views
I cant get an Input value with javascript

So i am trying to get the value of an input tag with javascript and show it on the console but it doesnot work at all. this is my code, what am i missing here?

const userTextValue = document.getElementById('user-text').value;


const show = () => {
  console.log(userTextValue);
}

const submit = document.getElementById('submit');

submit.addEventListener('click', show);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Access the input value when you click on show button, so that you get the updated value entered by user.

const show = () => {
  const userTextValue = document.getElementById('user-text').value;
  console.log(userTextValue);
}

const submit = document.getElementById('submit');
submit.addEventListener('click', show);
<div>
<input id="user-text" />
<button id="submit">Show</button>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

when you submit the page refresh by default to prevent that you can do it like this

const show = (e) =>{
    e.preventDefault();
    console.log(userTextValue);
}
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!