function bgInputInit(formId, options) { var form = $('#' + formId); if (typeof options.elements == 'object' && options.elements != null && $(form).size() == 1) { for (var element in options.elements) { var selector = '[name="' + bgInputEscape(element) + '"]'; $(selector, form).attr('emptybg', options.elements[element].background); $(selector, form).focus(function() { bgImageUpdate.call(this, 'focus'); }); $(selector, form).blur(function() { bgImageUpdate.call(this, 'blur'); }); $(selector, form).each(function(){ bgImageUpdate.call(this, 'blur'); this.style.backgroundRepeat = 'no-repeat'; }); } } return true; } function bgInputEscape(name) { //name = name.replace('[', '\\['); //name = name.replace(']', '\\]'); name = name.replace(':', '\\:'); name = name.replace("'", "\\'"); name = name.replace('"', '\\"'); return name; } function bgImageUpdate(func) { if (func == 'focus') { this.style.backgroundImage = ''; } else if (func == 'blur'){ if (this.value == '') { this.style.backgroundImage = "url('" + $(this).attr('emptybg') + "')"; } else { this.style.backgroundImage = ''; } } }