Reputation: 7
here is my code. I would like to print the variable 'fName' and the text prior into the div (with the ID 'feedback').
<script>
function myFunction() {
var first = document.getElementById("fName").value;
var last = document.getElementById("lName").value;
document.getElementById("feedback").innerHTML += "Hello" + fName;
}
</script>
Any help would be appreciated.
Upvotes: 0
Views: 1230
Reputation: 31
Just use the variables you have defined:
<script>
function myFunction() {
var first = document.getElementById("fName").value;
var last = document.getElementById("lName").value;
document.getElementById("feedback").innerHTML += "Hello " + first + " " + last;
}
</script>
Upvotes: 1