Arshak
Arshak

Reputation: 7

Writing text and a variable into HTML using Javascript

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

Answers (1)

Pfoerdie
Pfoerdie

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

Related Questions