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.

Regards,
Ankit Baphna

Recommended Answers

All 6 Replies

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?

Thanks,
Regards,
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.

Thanks,

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.

Regards,
Ankit

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

Example here: http://www.givemedeals.com/ - 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.

Regards,
A.B

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.