'How do you check if user typed the specific word inside a textarea?

How do you check if user typed the specific text inside the textarea tag? Here is an example

 </head>
 <body>
            
            <textarea>
                            
            </textarea>
            <div class="box">
                            
            </div>
            <script>
                            (this is just example)
                            
                            if = user typed inside textarea this =("display (hi)")
                            do = build element inside .box the user typed inside the () of the text "display" 
            </script>

I really don't know how to do it i try to search it but none appeared and if you're confused with code it just glitched



Solution 1:[1]

I hope it will give you idea. If use type any text and includes hi in textarea. It's will show all text in box container.

let textarea = document.querySelector("textarea");
let box = document.querySelector('.box');

textarea.addEventListener('keyup', (e) => {
  if (e.target.value.includes("hi")){
    box.innerHTML = "";
    box.append(`${e.target.value}`);
  }
})
<textarea></textarea>
<div class="box"></div>

Solution 2:[2]

With the JS string function includesyou can archive this.

let block = false;
const box = document.querySelector('.box');

  function check(e) {
    const match = e.value.includes("hi");
    if (match && block === false) {
    box.innerHTML = 'Hello again'
    block = true;
  }  
}
<textarea onkeyup="check(this)"></textarea>
<div class="box"></div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Maik Lowrey