Set default value in Textarea's if empty

1

I have two textarea on my page to give GET to the value I have in my database and I want to delete the text of the two textarea automatically set a default value there " inside. "

    
asked by anonymous 02.02.2015 / 01:54

1 answer

1

With JQuery you can do this in the .change event, this event fires when the value of an element changes . In this event it can be checked whether textarea is empty, if it is, we put a default value.

$('#text1').change(function(){
    if( $("#text1").val().length < 1){
        $('#text1').val('Valor padrão');
      }
});

DEMO

For versions prior to IE9 this can be done through the onpropertychange .

$('#text1').bind('input propertychange', function() {
    if( $("#text1").val().length < 1){
        $('#text1').val('Valor padrão');
      }
});

DEMO

    
02.02.2015 / 02:32