+ 1
How I can make the webpage alert if the input is empty, and write something if there as a value in the input?
2 ответов
+ 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);
}
}
+ 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();