View Full Version : Removing default value from text box on click...

12-15-2005, 04:10 PM
Hey all

I think this should be simple as ive seen it done many times.

I have a text box for my mailing list, which displays "enter your email" in the box as default. But I want this text to disappear, leaving the box blank, when the user clicks inside it.

This may be a javascript trick I suspect but either way if someone could show me how to clear the box when the user clicks into it, that would be great.


12-15-2005, 05:48 PM
You're right in thinking you'll need Javascript.


12-15-2005, 06:20 PM
Here is an example:

<script type="text/javascript">
function valueFocus(e,d) {
if(e.value == d) e.value = '';
function valueBlur(e,d) {
if(e.value == '') e.value = d;

<input name="email" id="email" onfocus="valueFocus(this,'Enter Your Email');" onblur="valueBlur(this,'Enter Your Email');" value="Enter Your Email" />

This way, if someone selects the input, enters nothing, then selects something else, 'Enter Your E-mail' will come back.

12-16-2005, 12:52 AM
Thanks Circusbred, that works perfectly!

Thanks for the link Mark87, I used the example given but thanks for your help also :D