0

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.

2
  • 1
    okay? what's the problem? Commented Nov 12, 2018 at 22:16
  • 1
    fName (variable) is not defined in the code you posted. Commented Nov 12, 2018 at 22:20

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.