This almost works. However, when leaving the field \"defaulttext\" appears rather than the original text value. Not sure how to most efficiently echo the variable inside default
Try this in your firebug:
$(function() { console.log($(this)) });
You will find out that
var defaultText = $(this).val();
is probably not what you want.
If initial value for the input is the default text, obtain it like this:
var defaultText = $('input[type=text]').val()
Be aware, that this will work correctly only if there is just one input text on your page.
And also remove quotes in:
$(this).val('defaultText');