How to remove extra space inside textarea
Asked Answered
D

7

26

I have a textarea which displays some data from "history" column in my database. For unknown reason there is nearly 1.5 line of extra space before the text. Anyone can give me some idea why does it happen? Here is my HTML piece:

<div>
  <table>
    <tr>
      <th > History:</th>
      <td>
        <textarea style="margin-left:90px";  name="history"cols="80"label="notes"rows="4"wrap="virtual"> 
        <?php echo $my_class->history;?></textarea>
      </td> 
    </tr>
  </table>
</div>

You can see the problem here:enter image description here

Discriminant answered 23/6, 2014 at 14:0 Comment(5)
Tried trimming $my_class->history in the echo?Nifty
I did try it but it doesn't sort that issueDiscriminant
Try reading answer from here : https://mcmap.net/q/535537/-textarea-whitespaces?rq=1Flycatcher
Its because your php tag is on a newline. It is reading in the whitespace from where <textarea> ends until php tag opens. Put this all on one line to fixGospel
You are right I-LOVE-2-REVIVE. Problem sortedDiscriminant
G
60

Its because your php tag is on a newline. It is reading in the whitespace from where <textarea> ends until php tag opens. Put this all on one line to fix.

Gospel answered 23/6, 2014 at 14:25 Comment(3)
Or for those still finding this question: use the CSS white-space: normal or (or any of the other collapsing rules)Roethke
I tried this one line solution but Mike'Pomax'Kamermans additional css rule worked for me. ThanksBrahma
"white-space: normal" won't remove the spaces, tabs and new-lines. It just won't show them, but they will remain on the field value.Contumelious
A
7

Put this all on one line for fix this issue.Make your code like this.

<textarea style="margin-left:90px";name="history"cols="80"label="notes"rows="4"wrap="virtual"><?php echo $my_class->history;?></textarea>
Aristocrat answered 26/5, 2017 at 7:27 Comment(0)
P
6

Just put your php open tag right after the textarea close tag.. Dont use line break.. And close php exactly before (as you have done).. This will erase all the whitespaces..

Putman answered 27/6, 2015 at 16:18 Comment(0)
E
6

I know its late but may help others.

use this when document indentation is required.

$('document').ready(function()
{
    $('textarea').each(function(){
            $(this).val($(this).val().trim());
        }
    );
});

Same Question : https://mcmap.net/q/88215/-can-39-t-remove-whitespaces-from-textarea

Elope answered 27/6, 2017 at 6:53 Comment(0)
B
2

$('textarea').val($('textarea').val().trim()) This did the job for me.

Baranowski answered 9/6, 2020 at 8:25 Comment(0)
B
1

I faced same problem but I found an answer of this question. When you write php code between textarea in another line or in new line then this problem occurs

To fix this problem write php code and textarea in one line

<div>
  <table>
    <tr>
      <th > History:</th>
      <td>
        **<textarea name="history"cols="80" label="notes"rows="4" wrap="virtual"><?php echo $my_class->history;?></textarea>**
      </td> 
    </tr>
  </table>
</div>
Blowsy answered 23/5, 2019 at 16:31 Comment(0)
C
0

you can break the opening tag as much as you want, like

<textarea id="COMMENTS" name="COMMENTS" rows="3" > as long as the </textarea> does not have blank spaces to the left

Cirilo answered 13/12, 2022 at 18:55 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Narine

© 2022 - 2024 — McMap. All rights reserved.