"placeholder" of "textarea" does not appear

Asked

Viewed 6,568 times

9

I have a textarea with a placeholder which according to the 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 the same!

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 is the placeholder is not appearing?

2 answers

10


The problem is that the placeholder appears only when the textarea is empty, without any text. Yours is not, you have inserted the indentation spaces in it.

Try:

<form action="" method="post">
    <div>
        <textarea id="message" name="message" placeholder="A sua mensagem"></textarea>
    </div>
</form>
  • 2

    As both answers speak of the same, it is accepted for having been put first.

6

In the case of tag textarea, to the placeholder function, tag opening and closing must be on the same line and no spaces.

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

So to use:

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

Fiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.