1

I am trying to get a value from the user (taskName input),save that value in a variable and then print the value to the console when a button (taskAdd button) is clicked.However,Once I click the button I don't get the value in my browser console window.

HTML:

<label for="taskName">New Task</label> 
<input type="text" id="taskName" name="task" placeholder="What is your task name?">

<input id="taskAdd" type="submit" value="Add task">

JavaScript:

function getInputValue () {
let userInput = document.getElementById("taskName").value;
console.log(userInput);
}
let addTask = document.querySelector("#taskAdd");
addTask.addEventListener("click", getInputValue());

1 Answer 1

1

Replace

addTask.addEventListener("click", getInputValue());

with:

addTask.addEventListener("click", getInputValue);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.