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

114
Views
input value on keyup (codepen)

I have an issue on this codepen https://codepen.io/Kimple/pen/MWEBGZy?editors=0011

In the function titleCheck(), I want to get the value of <input type="text" id="title" placeholder="title"> But I always get an empty value, and I don't know why.

I tried the same code on JSFIDDLE and had the same issue.

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

0

You saved the value into the variable when initialized, therefore when the input is empty. The value does not update itself automatically. You need to ask for it with every key press. This way it should log the correct value:

 function titleCheck() {
        title.addEventListener('keyup', (event) => {
            console.log(title.value) // ask for the value every time to see it updating
            titleValue = title.value
            if (titleValue != '') {
                checkBox.checked = true;
                checkboxCheck();
            } else {
                checkBox.checked = false;
                checkboxCheck();
            }
        })
    }
    titleCheck()

Also next time try using snippets in your answer instead of link to codepen or other external editor.

about 4 years ago · Juan Pablo Isaza Report

0

You have to reassign titleValue, because you set it to empty on beginning and don't change it afterwards

   function titleCheck() {
        title.addEventListener('keyup', (event) => {
            titleValue = document.getElementById("title").value
            console.log(titleValue)
            if (titleValue != '') {
                checkBox.checked = true;
                checkboxCheck();
            } else {
                checkBox.checked = false;
                checkboxCheck();
            }
        })
    }
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!