Auto Clear on Focus

A simpler approach to input handling. This script clears the contents of a text box as soon as the user clicks inside or tabs into it.

Copy the Script

<!-- Inline Method -->
<input type="text" value="Default Text" onfocus="this.value=''">

<!-- Function Method -->
<script>
function wipe(el) {
    el.value = "";
}
</script>

<input type="text" value="Click to clear" onfocus="wipe(this)">

Frequently Asked Questions

Yes. If the user types something, clicks away, and then clicks back, this simple version *will* clear their input. Be careful using this logic on important forms.

You must check if the current value matches the default value (like in the previous script) before clearing it.

It can be useful for search bars where users typically want to start a fresh search every time they click the box.