how to align text in textarea in html
Solution 1
Try 2 things:
- put all on 1 line
- trim the echoed value
So like this
<TEXTAREA rows = 10 cols = 95 name = answer5><?php echo trim(stripslashes(htmlentities($_POST['answer5']))); ?></TEXTAREA>
This because the textarea has some special rules that defy (as I call it) the normal markup rules. Never really understood it. But data inside textarea is always used as is, including leading and multiple spaces, etc. Even html comments inside textareas will be outputted.
Solution 2
Trimming is not a best option to go with.
It will trim all the spaces which are even needed. I had the same problem and what I did was made all the code in a single line.
It depends on the spaces which you have in your text. My code was sometime like this before
<div class="controls">
<textarea name="about" class="span12" id="terms" rows="5">
<?php include('includes/terms.php');?>
</textarea>
</div>
Now output which I was getting was like this:
Terms and Conditions
Point one
Point two
Point 3
Last Paragraph
// Here was huge space right at the bottom of textbox
So what is did was, modified my code this way:
<div class="controls"><textarea name="about" class="span12" id="terms" rows="5"><?php include('includes/terms.php');?></textarea></div>
Now everything is in single line and the spaces and new line entries which were there before are now gone. My text was printed like:
Terms and Conditions
Point one
Point two
Point 3
Last Paragraph
// Huge space is gone
You should also check the spaces which are there in the text contained in textarea element, apart from starting and ending points.
honey
Updated on June 04, 2022Comments
-
honey almost 2 years
I have a
textarea
and I am also writing some PHP code to prefill thetextarea
upon refresh. The "prefill" part is working fine.My problem is when I start to type in the
textarea
, the text is not left aligned. It is starting at some random point in thetextarea
box. I want it left aligned like a normal text box.Here is my code:
<TEXTAREA rows = 10 cols = 95 name = answer5> <?php echo stripslashes(htmlentities($_POST['answer5'])); ?> </TEXTAREA>