Gaurav Srivastava Gaurav Srivastava - 1 year ago 95
HTML Question

How to clear text field on focus of text field

I want to clear the text field when the user clicks on that

<input name="name" type="text" id="input1" size="30" maxlength="1000" value="Enter Postcode or Area" onfocus=="this.value=''" />

Answer Source

To do this you will need to use a scripting language, probably javascript. Here an example

<input type='text' value'Some text' onclick='javascript: this.value = ""' />

Hope this helps.


To meet what David is explain here is a second example in case that is what you are looking for

<script type='javascript'>
    var clear = true;
    function clear(obj)
            obj.value = '';
            clear = false;

<input type='text' value'Some text' onfocus='clear(this);' />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download