removing the default value for an input box

W

windandwaves

Hi Folk

For input boxes in forms, some forms have default values e.g. "enter
phone number here". When a user wants to enter their details, they
first have to remove the default entry - which can be a bit annoying
at times. I have written a very simple little script (obviously not
the first one) that removes the default entry. You can find it here:

http://www.sunnysideup.co.nz/j/form/

Cheers

Nicolaas
 
R

RobG

Hi Folk

For input boxes in forms, some forms have default values e.g. "enter
phone number here". When a user wants to enter their details, they
first have to remove the default entry - which can be a bit annoying
at times. I have written a very simple little script (obviously not
the first one) that removes the default entry. You can find it here:

http://www.sunnysideup.co.nz/j/form/

Some suggestions...

You should only apply the function to text inputs, not all input
elements.

When the control is blurred and nothing is entered, you return it to
the default value. However, when the control next receives focus, the
function doesn't fire. Onfocus you might like to test something like:

if (input.value == input.defaultValue) input.value = '';

You might be better off to apply the handler based on the control's
class, that way you can apply it to textarea elements too.
 
W

windandwaves

Some suggestions...

You should only apply the function to text inputs, not all input
elements.

When the control is blurred and nothing is entered, you return it to
the default value. However, when the control next receives focus, the
function doesn't fire. Onfocus you might like to test something like:

if (input.value == input.defaultValue) input.value = '';

You might be better off to apply the handler based on the control's
class, that way you can apply it to textarea elements too.

Thanks Rob.

MUCH APPRECIATE your comments - as always! Thank you. I will use
those ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top