tags:

views:

26

answers:

1

How can I use jQuery to add text labels inside input fields and text fields and when a user clicks inside the input field the text disappears like here on stackoverflow.

Looking for examples or tutorials.

+1  A: 
$('#textboxid').focus(function() {
    if(this.value == default_value) {
        this.value = '';
    }
});
$('#textboxid').blur(function() {
    if(this.value == '') {
        this.value = default_value;
    }
});
dejavu
+1 - This is correct, though it should be pointed out if you're not *already* using jQuery, the vanilla JS version is just as easy here, might consider adding it to your answer :)
Nick Craver
I cant get this to work:(
lone