PDA

View Full Version : Form Box


aceinstaller
02-17-2001, 11:29 AM
Hi. Can anyone tell me how to make a form box clear all of its contents on focus (someone clicking on it). I have looked everywhere for this script, but can't find it... please help..... (only want it to clear the box for the first time they select it, so it doesn't clear anything else they type in, only what was originally there when the got to the site)

Thanks

Andy

Jason
02-17-2001, 02:29 PM
Between the head tags:

<script LANGUAGE="JavaScript">

function clearfield(which){
if (which.value=="your@email.com")
which.value=''
}

</script>

Then for the text box:
<input type="text" name="email" size="20" value="your@email.com" onFocus="clearfield(this)">

[Edited by Jason on 02-17-2001 at 02:32 PM]

Jason
02-17-2001, 02:34 PM
P.S.

IMPORTANT

After which.value appears something that looks like this ", but it is actually two of these in a row '

aceinstaller
02-18-2001, 06:15 AM
Thanks. That worked great. I'm suprised there isn't some code like that out there on the net. I looked at javascript.com etc, but they didn't seem to have any code that did the job. Oh well...

Thanks again

Andy

Ian
02-18-2001, 06:42 AM
Andy, you were looking to far away from home. Try A1 JavaScripts next time, you will find that your answer was here.
http://www.a1javascripts.com/miscellaneous/clearform.html
Glad you got it anyway, thats the main thing. :)
Also there will be a series of tutorials on forms coming out on A1 in the near future, one of those also includes this script.

aceinstaller
03-05-2001, 04:10 PM
How would i do this with two or more boxes? I tried changing the which to something else, and the same to the form properties, but it gave me errors. Thanks in advance...

Andy

Ian
03-05-2001, 06:47 PM
Hi Andy,
Use the one on A1, you can use it in as many forms on one page as you like.

Simply place this in the head.

<script>

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
</script>

and this in all your forms:

onFocus="clearText(this)"

good luck.