+ 2

Javascript

Hi, using javascript, i would like to display message beside the textarea when it is empty, but my code doest run. How can solve this issue? <textarea name="abc" id="passage" rows="10" cols="10" onkeyup="display()"> </textarea> <span id="passageEmpty"></span> //script function display() { var lol = document.getElementById("passage").value; if(lol==null||lol=="") { document.getElementById("passageEmpty").innerHTML ="required"; } else { document.getElementById("passageEmpty").innerHTML =""; } }

19th Apr 2022, 9:58 AM
jhh
11 Respuestas
+ 3
jhh <textarea name="abc" id="passage" rows="10" cols="10"> </textarea> <span id="passageEmpty"></span> //script 👇👇👇👇👇👇👇👇here const passage = document.getElementById("passage") passage.addEventListener("input", display ) 👈 function display() { var lol = document.getElementById("passage").value; if(lol==null||lol=="") { document.getElementById("passageEmpty").innerHTML ="required"; } else { document.getElementById("passageEmpty").innerHTML =""; } }
19th Apr 2022, 10:20 AM
NonStop CODING
NonStop CODING - avatar
+ 2
Problem solved thank you
19th Apr 2022, 11:12 AM
jhh
0
try using event "input" by adding an event Listener
19th Apr 2022, 10:13 AM
NonStop CODING
NonStop CODING - avatar
0
Would u elaborate more in term of code?
19th Apr 2022, 10:14 AM
jhh
0
jhh passage.addEventListener("input", display )
19th Apr 2022, 10:15 AM
NonStop CODING
NonStop CODING - avatar
0
Do you mean span element value? It's working check again.. when empty, it showing "required" otherwise showing ""empty edit: jhh pls save code and share link
19th Apr 2022, 10:18 AM
Jayakrishna 🇮🇳
0
Within the function inside? Because my previous code come out error saying that the function is not a function at element
19th Apr 2022, 10:18 AM
jhh
0
Jayakrishna🇮🇳 yes this is what i meant, my code is basically like what i shown
19th Apr 2022, 10:22 AM
jhh
0
NonStop CODING how do i call the"display function()"
19th Apr 2022, 10:23 AM
jhh
0
jhh llook at my code at emojis
19th Apr 2022, 10:24 AM
NonStop CODING
NonStop CODING - avatar
0
jhh Yes Means, just check again your code. It's working.. edit: currently text area has a space. remove it and see...
19th Apr 2022, 10:30 AM
Jayakrishna 🇮🇳