Gaurav Srivastava Gaurav Srivastava - 5 months ago 11
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

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.

Edit:

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)
    {
        if(clear)
        {
            obj.value = '';
            clear = false;
        }
    }
</script>

<input type='text' value'Some text' onfocus='clear(this);' />