Search:

Soup of the Day

This is the archive of sam.clark.name

Please note

This is the archive for http://sam.clark.name. All commenting is disabled and there will be no further posts to this site.

TextBox Hint

After I decided to take my source site offline for the time being, I thought it would be best to post the contents here in the blog.

TextBoxHint is a Javascript script that puts a piece of hinted text into a form textbox before the user selects the box. When the box is selected, the text is instantly removed. If the user fails to input any text in the input box then the hint is restored.

Please be aware that if the user submits the form, it will pass the hints, so you will need to watch for that. I am currently working on a script to clear the hints as the form is submitted.

You can download the source javascript from http://www.polaris-digital.com/source/textBoxHint.js�

/**
*� � � TextBox Hint
*� � � Written by Sam Clark
*� © 2006 Polaris Digital Limited
* � � � Version 1.0
*
*� � � Released under the GNU Public Licence, Share-alike
*� � � You are permitted to use and modify this code, providing
* � � � your modifications are released under the same licence
*
*� www.polaris-digital.com
*/
function TextBoxHInt(inputBox, textHint)
{
if(!document.getElementById) return false;� � � � � � � � � � � � // If browser does not understand, get out now!
if(!document.getElementById(inputBox)) return false;� � � // If text box is not found get out!
var inputBoxId = document.getElementById(inputBox);� � � � � � // Assign the hbw_postcode to postCodeBox
inputBoxId.value = textHint;
inputBoxId.onfocus = function()� � � � � � � � � � � � � � � � � � � � � // When the user clicks in the box
{
if(inputBoxId.value == textHint)� � � � � � � � � � � � � � � // If the value is the default value
inputBoxId.value = '';� � � � � � � � � � � � � � � � � � � � � // Clear the box
}
inputBoxId.onblur = function()� � � � � � � � � � � � � � � � � � � � � // When the user clicks away from the box
{
if(inputBoxId.value == '')� � � � � � � � � � � � � � � � � � � � � // If the box is empty
inputBoxId.value = textHint;� � � � � � � � � � � � � � � // Fill the box with instruction
}
}� � �


Post Meta

  1. No comments yet.

Leave a Reply

You must be logged in to post a comment.