tags:

views:

287

answers:

5

I'm having a strange problem in that I have php inserting text into a <textarea> and the <textarea> is adding one white space to the top of my text.

I created an example page to display the problem... here it the code behind the page.

<textarea style="width:600px;height:100px;"><?php get_film_info('main description'); ?></textarea>
<br>
<textarea id="mainDescription style="width:600px;height:100px;">Text just typed in</textarea>
<br>
<?php get_film_info('main description'); ?>

You can see that without the <textarea> tag, the text does not include the indent. My database also reflects no indent, as well as the php output outside of the <textarea>...

Any clue what could be going on?

the sample page

-J

################################## EDIT

You were all right, of course I didn't bother checking the source code of the output file. Turns out when I was adding the data (via ajax) I was sending my data like var data = '&main_description= ' + mainDescription. <-- notice the space between the "=" and the "+".

Thank you all for your input, gotta just give the check mark to the guy on the top of the list.

-J

+1  A: 

There's definitely a space in the beginning and one at the end, as can be seen in the page source. Perhaps get_film_info() is inadvertently injecting them.

Ignacio Vazquez-Abrams
A: 

There is a heading space in the return value of get_form_info(). Check the value of 'main description' in your database (or whereever it is being stored). If there isn't a heading space in the value itself, then get_film_inflo() is to blame.

John Himmelman
+2  A: 

Your text has space at beginning! I don't know what function 'get_film_info' returns but it returns with space!

confiq
+4  A: 

Try this:

trim(get_film_info('main description'));
antyrat
A: 

A space does exist. Outside of the textarea, the browser does not interpret them, because a \n means nothing (it is interpreted in the source code only) in just regular text form. However, a \n inside a textarea represents a line break and is being interpreted as such.

To solve the problem you can always trim the value before outputting it.

animuson