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

jww
  • 97,681
  • 90
  • 411
  • 885
user2815059
  • 329
  • 2
  • 6
  • 12

7 Answers7

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.

Revive
  • 2,248
  • 1
  • 16
  • 23
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..

Giorgos Tsakonas
  • 5,845
  • 3
  • 17
  • 20
6

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>
Narendra Solanki
  • 1,042
  • 14
  • 20
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://stackoverflow.com/a/44773825/3775083

2

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

hackernewbie
  • 1,606
  • 20
  • 13
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>
Sumit Kumar Gupta
  • 2,132
  • 1
  • 22
  • 21
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

  • 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](/help/how-to-answer). – Community Dec 16 '22 at 15:48