SurfnLearn.com

Making a Form Clear When Clicked

This little javascript can be used to clear a form’s value when the user clicks on it.

Making a form clear when clicked

Add this code between the <head></head> tags on your page:

[php] <script>
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = “”

</script>
[/php] Once done you can now add your forms anywhere on the page and as many as you want like this:

Add this code between the body tags on your page:

[php] <form>
<input type=”text” value=”Enter your e-mail address..” onFocus=”clearText(this)”>
<input type=”text” value=”Search this site..” onFocus=”clearText(this)”>
</form>
[/php]

Join Our Community

Enter your email ID below to get access to all our awesome resources and be a PRO in your field.

You have Successfully Subscribed!

Sponsors

Did You Like Our Post? Sign Up Below and Get Latest Content Directly Delivered to Your Inbox

Enter Your email ID and be the first one to know when the new post gets published on SurfnLearn.

You have Successfully Subscribed!

Exit mobile version