This is really very simple to do:
Code:
var fld = document.getElementById('txtsearch');
fld.onfocus = function() {if (fld.value === fld.defaultValue) fld.value = '';};
That will clear the default text from the <input id="txtsearch" ... > field when your visitor accesses the field to start entering something.
If you want to put the original value back if they exit the field without typing anything you would add one extra line:
Code:
fld.onblur = function() {if (fld.value === '') fld.value = fld.defaultValue;};
You can change the value in the input tag itself to change the default value without needing to change the script at all. Similarly you can apply the same code to other fields just by changing the value of the id.
To make it easy to apply to as many fields as you like you can make it a function and pass the id of the field to add the code to:
Code:
var hideDef = function(id) {"use strict";
var fld = document.getElementById(id);
fld.onfocus = function() {if (fld.value === fld.defaultValue) fld.value = '';};
fld.onblur = function() {if (fld.value === '') fld.value = fld.defaultValue;};
};
hideDef('txtsearch');
hideDef('anotherid');
Bookmarks