Code1: <input id="text" type="text" name="fname" value="First Name" onclick="this.value='';"/>

Hi Friends,

Code1 - this print in my text box value "First Name". onclick this value gets erased so I can type Name.
but if I go to second text box and come back to this text box to modify or add more character my earlier value gets erased due to onclick.

How to make this edit/modifiable possible without erasing text which I wrote earlier.

Example: I write ANKIT
Then I move to second text tab
Then I move to first text tab to add another letter in Ankit to make it ANKITT

but the moment I bring my cursor ANKIT itself gets erased.

Without erasing ANKIT how can I retain this as well able to add/modify another text in it.

Ankit Baphna

This is html, not php, even if you are doing this in a php page. Read the HTML documentation online for help with this.

my mistake its HTML, by mistake I wrote it in subject line.

Could you suggest way out for this to achieve. is it possible?

Ankit Baphna

Your onclick event erasing text since it's cannot detect you wrote something there before.

Recent days, people rarely use onclick event for removing default text. now standard is placeholder, which will hold your text hint for user.

Try this:

<input id="text" type="text" name="fname" value="" placeholder="First Name" />

When user start typing, default text will be vanished.


in placeholder user will have to manually remove this text "First Name" from input box and then write his name.

But then how on Facebook registration form is using feature what I am looking for. on click "First name" gets erased as well text written afterwards do not get erased on second click on it.


With placeholder user don't have to manually remove "First Name", it'll automatically erased when user clicked first time.

Example here: - See the search box on top right area. "Search Deals" text is showing by placeholder.

Facebook is using placeholder as well.

Ok I got it. Now its working for me.

Thanks a lot.