简体   繁体   中英

How I get value from textarea and check it?

Here's my html code:

 if(document.getElementById("txtArea").value = "मैं ये क्यों करू"){ document.getElementById("hidden").innerHTML = "Correct answer!"; }
 <h2>Translate this english paragraph to hindi</h2> <h3>Why should I do this?</h3> <textarea id="txtArea" placeholder="Write the correct hindi translation here"></textarea> <h1 id="hidden" style="color:green"></h1>

Actually I am trying to get the value that user had inputted in my textarea. And check whether it(value entered by user) is right or not. How will do it?

Listen to textarea input change

 const txtAreaEl = document.getElementById("txtArea") txtAreaEl.addEventListener('keyup', function(event) { document.getElementById("hidden").innerHTML = event.target.value === "मैं ये क्यों करू" ? "Correct answer!" : null; })
 <h2>Translate this english paragraph to hindi</h2> <h3>Why should I do this?</h3> <textarea id="txtArea" placeholder="Write the correct hindi translation here"></textarea> <h1 id="hidden" style="color:green"></h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM