Javascript search box click text disappear out of focus when the text appears

  • 2020-03-30 03:57:38
  • OfStack

When in focus, the text disappears, and when out of focus, the text appears


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Headless document </title>
</head>

<body>
<input id="text" type="text" value=" Click and I disappear "/>
<script>
var oText=document.getElementById("text");
var onoff=true;
oText.color="#000";
oText.onfocus=function(){
if(onoff){
this.value="";
this.color="red";
onoff=false;
}
}

oText.onblur=function(){
if(this.value==''){
this.color="#000";
this.value=" Click and I disappear ";
onoff=true;
}
}
</script>
</body>
</html>


Related articles: