Clear Input Field (HTML + JavaScript)

Clear Input Field on Focus:

<!-- When the input field gets focus, replace its current value with an empty string -->
<input type="text" onfocus="this.value=''" value="Test text">

Clear Input Field with a Button:

<button onclick="document.getElementById('myInput').value = ''">Clear input field</button>
<input type="text" value="Blabla" id="myInput">

Leave a Reply

Your email address will not be published. Required fields are marked *