Alex Rivera | Logout

Why is textarea filled with mysterious white spaces?

Asked 2010-02-04T20:35:33.937
385

I have a simple text area in a form like this:

<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink">
<?php     if($siteLink_val) echo $siteLink_val;?> 
                            </textarea>

I keep getting extra white space in this textarea. When I tab into it my cursor is like in the middle of the textarea and not in the beginning? What is the explanation?

Edit
Report

1 Answer

650

Look closely at your code. In it, there are already three line breaks, and a ton of white space before </textarea>. Remove those first so that there are no line breaks in between the tags any more. It might already do the trick.

Note that if($siteLink_val) condition is superfluous in this case and can be safely removed.

What is more important, all HTML output must be obligatory HTML-encoded. Hence your code could be like this

<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink"><?php 
    echo htmlspecialchars($siteLink_val);
?></textarea>
answered 2010-02-04T20:37:12.780

Your Answer