"placeholder" from "textarea" does not appear
I have a textarea
with a placeholder
which according to the documentation ( is perfectly valid and should work:
Example in JSFiddle
Part of 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!
Generated HTML:
<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 isn't placeholder
showing up?
9
2 answers
The problem is that the placeholder appears only when the textarea is empty, with no text at all. Yours is not, you have inserted the spaces of the ID in it.
Experiments:
<form action="" method="post">
<div>
<textarea id="message" name="message" placeholder="A sua mensagem"></textarea>
</div>
</form>
10
Author: Guilherme Bernal, 2014-01-23 13:13:50
In the case of the textarea
tag, for the placeholder
to work, the opening and closing of the tag must be on the same line and without spaces.
In your case textarea
thinks the line break is content and placeholder
does not appear.
Thus one should use:
<textarea id="message" name="message" placeholder="A sua mensagem"></textarea>
Fiddle
6
Author: Sergio, 2020-06-11 14:45:34