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

146
Views
Why is my input value equal '' when I retrieved with a button click event?

Why does the activityInput.value always equal an empty string. This seems very simple, I feel stupis asking something so simple but I cant get it to work. Please help me!

function addActivityListEntry(){
    
  let activityListContainer = document.getElementById('activityList');
       let newActivity = document.querySelector("#activityListInput").value
       console.log(newActivity)
 };

let activitySubmitButton = document.getElementById('activitySubmit');
activitySubmitButton.addEventListener('click', e => {
  e.preventDefault();
  addActivityListEntry()
 })
 <div id = "activityListContainer">
      
          <input type ="text"  class = "input" value = '' id = "activityListInput"  name = "activityListInput" >
          <label for = 'activityListInput'></label>
          <button  class = "button" id = "activitySubmit">
              submit activity
          </button>
    
        <div id = 'activityList' ></div>
</div>

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

0

I can't seem to find where there should be an

activityInput.value

all you have is an

activityListInput.value

This html file should work and shows the logs for "activityListInput"

 <!DOCTYPE html>
<head></head>
<body>
    
    <div id = "activityListContainer">
        
    <input type ="text"  class = "input" value = '' id = "activityListInput"  name = "activityListInput" >
    <label for = 'activityListInput'></label>
    <button  class = "button" id = "activitySubmit">
        submit activity
    </button>
    
    <div id = 'activityList' ></div>
</div>

</html>
<script>
    function addActivityListEntry(){
    
    let activityListContainer = document.getElementById('activityList');
         let newActivity = document.querySelector("#activityListInput").value
         console.log(newActivity)
   };
  
  let activitySubmitButton = document.getElementById('activitySubmit');
  activitySubmitButton.addEventListener('click', e => {
    e.preventDefault();
    addActivityListEntry()
   })
</script>
</body> 
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!