"placeholder" of "textarea" does not appear

7

I have textarea with placeholder that according to documentation (English) is perfectly valid and should work:

Example in JSFiddle

Part of the form

<?php

/* Apenas o código referente à textarea
 */
$oc_message = isset($postArr["oc_message"]) ? cleanStr($postArr["oc_message"]) : '';

$form = '
<div class="form-group">
    <label for="oc_message">
        '.ucfirst(I18N_WORD_MESSAGE).' <small class="text-danger">*</small>
    </label>
    <textarea class="form-control" id="oc_message" name="oc_message" placeholder="'.I18N_PLACEHOLDER_MESSAGE.'" rows="10">
       '.$oc_message.'
    </textarea>
</div>';
?>

However, the text of placeholder does not appear in it!

HTML generated:

<div class="form-group">
    <label for="oc_message">
        Mensagem 
        <small class="text-danger">*</small>
    </label>
    <textarea rows="10" placeholder="Introduza a sua mensagem" name="oc_message" id="oc_message" class="form-control">                          
    </textarea>
</div>

Question

Why does placeholder not appear?

    
asked by anonymous 23.01.2014 / 13:50

2 answers

8

The problem is that the placeholder appears only when textarea is empty, with no text at all. Yours is not, you have entered the indentation spaces in it.

Try it out:

<form action="" method="post">
    <div>
        <textarea id="message" name="message" placeholder="A sua mensagem"></textarea>
    </div>
</form>
    
23.01.2014 / 13:54
5

In the case of the tag textarea , for placeholder to work, opening and closing the tag must be on the same line and without spaces.

In your case, textarea thinks that the line break is content and placeholder does not appear.

So you should use:

<textarea id="message" name="message" placeholder="A sua mensagem"></textarea>

Fiddle

    
23.01.2014 / 13:54