skip to Main Content

Clear Field on Focus

Did you ever have the need to put an initial value on an input field? Here’s a nifty little code to do just that. Below is a sample “Zip” input field. Play around with it and copy and adapt the code to your forms..

<input style="width: 64px;" value="Zip" onfocus="if(this.value == 'Zip') { this.value = ''; }" onblur="this.value=this.value==''?'Zip':this.value;" type="text" name="ZipField"/>

Just change the value "Zip" with whatever value you need to change it to, like "Address" or "Phone Number" or "City", etc.


Editorial Staff at ETN Multimedia is led by Alphonse Tan. Page maintained by Alphonse Tan

Back To Top