Clear the text box content when a text box becomes the focus

  • 2020-03-30 02:44:20
  • OfStack

 
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title> Clear text box content when in focus </title> 
<script> 
window.onload = initAll; 

function initAll(){ 
var clearText = document.getElementsByTagName("input"); 
for (var i=0; i<clearText.length; i++){ 
clearText[i].onfocus = function ( ){ 
this.value = ""; 
} 
} 
} 
</script> 
</head> 

<body> 
 Text box 1: <input type="text" name="text" id="clearText1" value=" Clear the contents of textbox 1 "/><br/> 
 Text box 2: <input type="text" name="text" id="clearText2" value=" Clear the contents of text box 2 "/><br/> 
 Text box 3: <input type="text" name="text" id="clearText3" value=" Clear the contents of text box three "/> 
</body> 
</html> 

Related articles: