Free web development scripts for the webmasterDevelopment Scripts

 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 5 users online
 o Most users online: 67
 o Home
  o Javascripts
   o Forms Manipulation
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o OxyScripts
 o Open Source Design
 o devnet
 o designplace
 o Free Wedding Websites
 o Wedding Vendor Directory

Clear a textfield when a user clicks on it (Rated 0)

Description:

The trick is to only clear the textbox when the default text is displayed - so the user doesn't lose their input. This is done by comparing the value in the textbox and the value in a hidden field.

Code starts here


<script>
function clearText(textElement, defaultElement)
{
if (textElement.value == defaultElement.value)
{
textElement.value = "" ;
}
}
</script>

<form name="myForm">
<input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText(this, document.myForm.defaultText);">
<input type="hidden" name="defaultText" value="Enter keyword here...">
</form>


Submitted by MattK on 06-01-2006 8:35


Rate This Script

User Contributed Comments

Registered Members login
© Copyright 2003 - Devscripts.net