Domanda

I have <textarea></textarea> on my html page and want to retrieve info from it based on what the user types into it. Say if the user types "Hello" in the textarea. "How are you" will appear.

Like so (code doesn't actually work, but just an example:

<script>    
    if ('msg'.value === "hello") {
        document.write("How are you");
    }
</script>
<textarea  id="msg"></textarea>
<input type="submit></input>

Hope that someone can help me out!

Edit: outputs the msg val, on submit.

Thanks!

È stato utile?

Soluzione

'msg' is a string. You need an element:

if (document.getElementById('msg').value === "hello") {
    document.write("How are you");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top