Click to Clear Input
Enhance form usability. This script ensures that default instructions (like "Enter Name Here") vanish instantly when the user clicks to type.
Copy the Script
<script>
function clearMe(input) {
input.value = "";
}
</script>
<!-- Simple Inline -->
<input type="text" value="Default Text" onclick="this.value=''">
<!-- Using Function -->
<input type="text" value="Default Text" onclick="clearMe(this)">
Frequently Asked Questions
`onfocus` triggers when you tab into a field OR click it. `onclick` only triggers on mouse clicks. Use `onclick` if you want keyboard tabbing to preserve the text.
Yes. You can store the original value in a data attribute (e.g., `data-default='Search...'`) and restore it `onblur` if the field is empty.
Yes, but you should generally avoid putting default text in password fields for security and usability reasons.