How to clear HTML input field value on focus in JavaScript

2 Answers

0 votes
<input type="text" value="abc" id="iid"/>
const inputText = document.getElementById("iid");

inputText.addEventListener("focus", ()=>{
   inputText.value = " ";
})  
    
    
    
/*
run:

    
*/

 



answered Jun 17, 2021 by avibootz
0 votes
<input type="text" value="abc" id="iid" onfocus="this.value=''"/>

 



answered Jun 17, 2021 by avibootz
...