/ Published in: JavaScript
Public domain. Will overwrite any existing classes of the element it is applied to, so use my add/remove CSS classes script if you want to retain current classes.
UPDATED 2/25/2011: get function added. Script would have failed without this, unless you changed all instances of get to document.getElementById.
Add styling (e.g. change the font color) of the labels by using the "label" class.
Expand |
Embed | Plain Text
function get(elmnt) { return document.getElementById(elmnt); } function addLabel(elmnt, label) { if(get(elmnt).value.replace(/\s/g, '')=='') { get(elmnt).className = 'label'; get(elmnt).value = label; } get(elmnt).onfocus = function() { if(this.className=='label') { this.value = ''; this.className = ''; } }; get(elmnt).onblur = function() { if(this.value.replace(/\s/g, '')=='') { this.className = 'label'; this.value = label; }; } }
You need to login to post a comment.
