Вопрос

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!

Это было полезно?

Решение

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

if (document.getElementById('msg').value === "hello") {
    document.write("How are you");
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top