I'm learning Javascript and I'm trying to input a text in a field, click on a button and change a paragraph innerHTML.
I've already done that successfully. But now I want to make a correction on the field, but when I click the button, nothing happens.
//These are the variables
var name = document.getElementById("name").value;
var bt = document.getElementById("bt");
var para = document.querySelector("p#paragraph");
//event calls the insert().
bt.addEventListener("click", insert);
//The function changes the innerHTML
function insert() {
para.innerHTML = name;
}
//The textfield to input the name
<input type="text" id="name" placeholder="Your name here"> <br> //The button
<input type="button" value="Click" id="bt"> //The Paragraph to be changed
<p id="paragraph">...</p>