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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.