Anthony Russo
Anthony Russo

Reputation: 931

onfocus remove text from textarea

I have looked on google to find a way to remove text on focus but couldn't figure our how to add it back if nothing was typed in the field.

This is what I have so far...

onfocus="if(this.value == 'Name*') { this.value = ''; }" value="Name*"

This will remove the "Name*" but then it is completely removed for good even if I don't type in the field.

Upvotes: 1

Views: 671

Answers (3)

Danny
Danny

Reputation: 468

Use the onblur event, with a similar if statement saying if it equals nothing then this.value should equal my place holder text.

onblur="if(this.value==''){this.value='Name*';}"

onblur

Upvotes: 1

PraveenVenu
PraveenVenu

Reputation: 8337

Use JQuery

$("textarea").focus(function() {

    if( $(this).val() == "Name*" ) {
        $(this).val("");
    }

});

Upvotes: 0

JNDPNT
JNDPNT

Reputation: 7465

This is what you are looking for: http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text

Upvotes: 0

Related Questions