Thought I’d save this handy dandy function for later.
Makes the text in an input disappear when you click on the input.
// the function:
function textReplacement(input){
var originalvalue = input.val();
input.focus( function(){
if( $.trim(input.val()) == originalvalue ){ input.val(''); }
});
input.blur( function(){
if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
});
}
function textReplacement(input){
var originalvalue = input.val();
input.focus( function(){
if( $.trim(input.val()) == originalvalue ){ input.val(''); }
});
input.blur( function(){
if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
});
}
// how to use:
textReplacement($('#inputname'));
textReplacement($('#inputname'));
Example:
teste
Oh. Did you think my comment form used the script? HA HA. That would only make sense of me to do. Um. I’ll have to implement it later as I’m in Nice at the moment.
SRYS.
AH .val() .. now I remember!
Very nice. I was looking for this!
can i use $(input[type=text]) as the parameter??
Yup, anything that returns an input/textarea should be fine.
not really,
I had to use this:
$(‘input[type=text]‘).each(function(index, obj){
textReplacement($(obj));
});
Anything that returns an input/textarea should be fine.
An array is a different story :). You’re correct, the function isn’t made to handle more than one element.
nice man, nice…i love jquery
i want to join with you
and what if I want to write “Click to Disappear” in the textbox?
thank you for this bro
really useful
this is the code i use
$(‘#buscardor’).focus(
function(){
if($.trim($(this).val()) == $(this).val()){
$(this).val(”);
}
}
);
$(‘#buscador’).blur(
function(){
if($.trim($(this).val()) == ”){
$(this).val($(this).val)
}
}
)