Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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}`);
  }
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading