Just refactored the input watermarking script, of course it is still XHTML 1.0 transitional and WCAG priority 1,2 valid.
JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// This Javascript is written by Peter Velichkov (http://www.creonfx.com) // and is distributed under the following license : http://creativecommons.org/licenses/by-sa/3.0/ // Use and modify all you want just keep this comment. Thanks var values = new Array(); var inputs = new Array(); function addWaterMark(el){ try { values.push(el.value); el.addEvent('focus',function(){ if (el.value === values[inputs.indexOf(el)]){el.value = ''}; }); el.addEvent('blur',function(){ if(this.value === ''){el.value = values[inputs.indexOf(el)]}; }); } catch(e) {dbug.log('addWaterMark: ', e)} }; window.addEvent('domready', function(){ inputs = $$('input.watermark'); inputs.each(addWaterMark); }); //--> |
Usage: Just put value on you inputs and use class=”watermark”
As usual example