+ 2

How I can ckeck the contenent of a textarea?

Hey! I have a problem. I want to check the contenent of a textarea whit javascript. I maked that : HTML : <textarea id="a"></textarea> <input type="submit" onclick="go()"> Javascript : const text = document.getElementById("a"); function go(){ if(text == "ah"){ alert("test") } } Somebody can help me?

17th Apr 2018, 5:16 PM
Kylia Baumann
Kylia Baumann - avatar
6 Answers
+ 4
const text = document.getElementById("a"); function go(){ if(text.value == "ah"){ alert("test") } }
17th Apr 2018, 5:34 PM
MO ELomari
MO ELomari - avatar
+ 3
https://code.sololearn.com/WhxPUg3jQ2us/?ref=app as you can see, doing as Mohamed ELomari suggested (text.value) will solve your problem
17th Apr 2018, 6:10 PM
seamiki
seamiki - avatar
+ 1
I think you have to put a .value after the GetElementById to get the contents of the textarea
17th Apr 2018, 5:26 PM
Bebida Roja
Bebida Roja - avatar
+ 1
Ok =/ Because on pgone it doesn't work .... I will use inputs (idk why but whit inputs it work...)
17th Apr 2018, 6:26 PM
Kylia Baumann
Kylia Baumann - avatar
- 1
No, he dind't work....
17th Apr 2018, 5:38 PM
Kylia Baumann
Kylia Baumann - avatar
- 1
Anwriter and the reader of my phone..
17th Apr 2018, 6:01 PM
Kylia Baumann
Kylia Baumann - avatar