I'm trying to make a simple on-focus clearer/on-blur restorer for forms on a site and I can't for the life of me figure out why this doesn't work.
$(document).ready(function() {
$('.form-text').focus(function(keeper) {
var keeper = $(this).attr('value');
if($(this).val() == keeper) {
$(this).val('');
}
return false;
});
$('.form-text').blur(function(keeper) {
if($(this).val() == '') {
keeper;
}
return false;
});
});
Any thoughts?
Just make keeper
in a outer scope, no need to be global.
And var keeper = $(this).attr('value'); if($(this).val() == keeper)
will always true, so that is not necessary.
$(document).ready(function() {
var keeper;
$('.form-text').focus(function() {
keeper = $(this).val();
$(this).val('');
return false;
});
$('.form-text').blur(function() {
if($(this).val() == '') {
$(this).val(keeper);
}
return false;
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With