All Things Techie With Huge, Unstructured, Intuitive Leaps

Quick Tip: Clear an HTML Input When You Click On It

How does one clear an html input, when you click on it or it gets focus? I had to look this up, and anything that I have to look up, I reprint to help others find it quickly.

In any mobile app, it is a real pain to remove input text if you have to replace it. It is much easier to have it automagically clear when anyone clicks on it to give it focus in order to change it.

Here is a simple way of doing it. Just add this attribute to the input tag:

onfocus="this.value='';"

The value for this.value is a single quote (') repeated for the null. Easy Peasy!

No comments:

Post a Comment