Lucas Angeli
Lucas Angeli

Reputation: 53

JS code not working

i need your help. I am a beginner in the programming area, i'm still doing a couple of basics courses.. Anyway, i'm trying to make a code work, but i'm not being able to.. hope some of you can help me. I'll post the code and explain what I'd like to do.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
<title>My Quiz</title>
</head> 
  <body>
   <input type="button" value="OK" onclick="funcao();">
   <textarea id="output"></textarea>
   <br>
   <script>
     function funcao(){
        document.getElementById("output").value;
       alert("Let me guess, you wrote that: " + output);
      }
   </script>
</body>
</html>  

As you can see, i'd like to take what the user typed and then show it on the screen. I made a function called (funcao) for that. But instead of showing me what the user typed it appears a message: [HTMLTextAreaElement]

I'll be glad if anyone can point me what i'm doing wrong. Big thx! Cheers from Brazil!

Upvotes: 0

Views: 50

Answers (3)

Zee
Zee

Reputation: 8488

You need to assign the value to output.

function funcao(){
    var output=document.getElementById("output").value;
    alert("Let me guess, you wrote that: " + output);
}

Upvotes: 0

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

You need to store output to a variable

function funcao(){
    var output = document.getElementById("output").value; // declare output variable here
    alert("Let me guess, you wrote that: " + output);
}

Upvotes: 2

antyrat
antyrat

Reputation: 27765

You forget to assign textarea value to output variable:

function funcao(){
    var output = document.getElementById("output").value;
    alert("Let me guess, you wrote that: " + output);
}

Upvotes: 0

Related Questions