+ 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 =""; } }
11 Réponses
+ 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 ="";
}
}
+ 2
Problem solved thank you
0
try using event "input" by adding an event Listener
0
Would u elaborate more in term of code?
0
jhh
passage.addEventListener("input", display )
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
0
Within the function inside?
Because my previous code come out error saying that the function is not a function at element
0
Jayakrishna🇮🇳 yes this is what i meant, my code is basically like what i shown
0
NonStop CODING how do i call the"display function()"
0
jhh llook at my code at emojis
0
jhh Yes Means, just check again your code. It's working..
edit:
currently text area has a space. remove it and see...