+ 1

How I can make the webpage alert if the input is empty, and write something if there as a value in the input?

https://code.sololearn.com/WjW7NjB1yefw/?ref=app

23rd Jun 2017, 4:37 PM
Walid Kh. Sharaiyra
2 odpowiedzi
+ 1
Used this Js function display(){ var text = document.getElementById("text").value; var empty = ' ' ; if (text == empty){ alert ("Please enter something in the input"); } else { document.write (text); } }
23rd Jun 2017, 4:59 PM
AL Emran
AL Emran - avatar
+ 3
@Ai Emran is right in your code as in linkjust replace = by == to make if(text.value==... that's why it was not showing result you need to replace it or try this var text=document.getElementById("textbox"), function check(){ if(text.value){ document.write(text.value); } //in case it's empty else{ alert("please enter something"); } } document.getElementById("button").onclick=check();
23rd Jun 2017, 5:07 PM
Sandeep Chatterjee