How TO – Clear Input Field


Previous


Next

Learn how to clear an input field on focus.


Click on the input field to clear it:

Clear Input Field on Focus

Example

<!DOCTYPE html>
<html>
<body>

<p>Clear the input field when it gets focus:</p>
<input type=”text” onfocus=”this.value=”” value=”Blabla”>

</body>
</html>

Clear Input Field with a Button

Example

<!DOCTYPE html>
<html>
<body>

<p>Clear the input field when you click on the button:</p>
<button onclick=”document.getElementById(‘myInput’).value = ””>Clear input field</button>

<input type=”text” value=”Blabla” id=”myInput”>

</body>
</html>


Previous


Next

Scroll to Top