I happened to write a function to do exactly this today and found your post. This function handles password field swapping by using a setTimeout() with a delay of 1 so the next "frame" of execution can focus on the element. Just call watermark() from a document.ready() context.
/** Support outerHTML in all browsers, from http://www.briangrinstead.com/blog/jquery-outerhtml-snippet */
$.fn.outerHTML = function() {
var doc = this[0] ? this[0].ownerDocument : document;
return $('<div>', doc).append(this.eq(0).clone()).html();
};
/** Lightweight way to have subtle title instructions in text fields. */
function watermark(exclude) {
if (!exclude) exclude = '';
$('input[type="text"], input[type="password"]').each(function(){
var self = this;
function setTitle() {
if (self === document.activeElement) return; // Don't change the currently focused field
if (self.value.length == 0 && !$(self).is(exclude)) {
$(self).addClass('textLabel');
if ($(self).attr('type') == 'password') {
var newSelf = $($(self).outerHTML().replace(/type=["]?password["]?/i, 'type="text"')).get(0);
$(self).replaceWith(newSelf);
self = newSelf;
$(self).data('restorePassword', true).focus(focus).blur(blur);
}
self.value = $(self).attr('title');
}
}
setTitle();
function focus(){
if(self.value == $(self).attr('title')) {
$(self).removeClass('textLabel');
if ($(self).data('restorePassword')) {
$(self).removeData('restorePassword');
var newSelf = $($(self).outerHTML().replace(/type=["]?text["]?/i, 'type="password"')).get(0);
$(self).replaceWith(newSelf);
self = newSelf;
setTimeout(function() {$(self).focus().focus(focus).blur(blur);}, 1);
}
self.value = '';
}
}
function blur(){
setTitle();
}
$(self).focus(focus).blur(blur);
});
}