Javascript - Delete a field of a form when clicking (focus)

Last update on March 3, 2009 09:40 AM by jak58
Published by jak58

Delete a field from an Html form when clicking (focus)


It is certainly happened to fall on an HTML form with values pre-filled for example describing the type of expected value.

Though it may be useful under certain circumstances, if you have to delete all the data to enter other ones it could be tiresome

It is possible to remove it as soon as the user selects the field:


<form  ... >
<input type="text" name="name" size=16 value="Enter your name" onFocus="javascript:this.value=''" />
<input type="submit" value="Validate" />
</form>


But using this method all the text will be erased whatsoever!
You can use a condition to replace only if the value is "Enter your name:

<input onclick="if(this.value=='Enter your name)this.value=''; ... />
Best answers for « Javascript Delete a field of a form when clicking (focus) » in :
Disabling right click on your webpage Show Disabling right click on your webpage More than often, while trying so save some text or pictures from a website, you might wonder why your right click is not allowed. This is a simple JavaScript code that has been inserted in the website...
Restrict Right click of mouse ShowRestrict Right click of mouse On your website, for protection of source code and photos, it is possible to restrict visitor from right click on your web page. Place this script between the tags and of your HTML...
IBook, PowerBook, MacBook (Pro): The Delete key ShowiBook, PowerBook, MacBook (Pro): The Delete key The keyboard of Apple laptops does not have a delete key, when you need to delete a file, you must drag it to the recycle bin, or through a right click on the file. This is tedious...
Escape an apostrophe under javascript ShowEscape an apostrophe under javascript In Javascript, an apostrophe (single quote) into a string itself enclosed by apostrophes cause an error. To troubleshoot, you should escape the apostrophe by heading the backslash character to get...
Download Recover Deleted Fat File 2 ShowRecover Deleted Fat File is a recovery tool for hard disks. It allows to restore damaged, corrupt, formatted, overwritten, deleted files. The application supports the following file systems: FAT12, FAT16, FAT32, SATA, ATA, SCSI and the following...
HTML forms ShowForms Interactive forms let web page authors give their pages interactive elements, such as for receiving messages from their readers, much like the reply cards found in some magazines. The reader enters information by filling in fields or clicking...
Hyperlinks ShowIntroduction to anchors Hypertext links or hyperlinks (anchors) are HTML elements that, when clicked on, enable readers to visit a new address. Hyperlinked text is underlined by default. Hyperlinks are what connect web pages to one another. They...