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
You're not referencing the variable defaultText
. You're passing a string since it's wrapped in quotes.
$(function() {
var defaultText = $('input[type=text]').val();
$('input[type=text]').focus(function() {
$(this).val('');
});
$('input[type=text]').blur(function() {
$(this).val(defaultText); // fixed!
});
});