Question #41420298
What is wrong with this basic Javascript code?
HTML
<h1 id="title">JavaScript Example</h1>
<input type="text" id="myTextBox" />
<input type="submit" value="Click Me" id="submit" />
JavaScript
function substitute() {
var myValue = document.getElementById("myTextBox").value;
if (myValue.length == 0){
alert('Please enter a real value in the text box!');
return;
}
var myTitle = document.getElementById('title');
myTitle.innerHTML = myValue;
}
document.getElementById("submit").addEventListener("click", substitute);