Remove extra space inside textarea?

Hi, does anyone know why i get extra spaces at the start when using textarea??

I don’t want the text indented on the first line of my textarea, i’m using…

<textarea>
This is an example text…
</textarea>

Any help would be great?

you can use a bit of javascript to do that.

suppose your textarea has id=“myTextArea”

if by “extra spaces” you mean leading and trailing white space, then executing the following function will achieve this any time after the page loads (perhaps you want to target some other event however).

function removeTextAreaWhiteSpace() {
var myTxtArea = document.getElementById(‘myTextArea’);
myTxtArea.value = myTxtArea.value.replace(/^\s*|\s*$/g,‘’);
}

the replace function in this case basically says “replace all leading or trailing white space with an empty string”

hope this helps!

Yes, it’s because you have white-space characters between the tags and the text. :slight_smile:

Remove that space if you don’t want it there:

<textarea rows="5" cols="80">This is an example text...</textarea>

(Note that the rows and cols attributes are required for textarea elements.)

ahhh, perhaps I’d misinterpreted… thought it was a more general question :slight_smile:

Great answer AutisticCuckoo sounds like that was it as I read it again…

Your post is still valuable, JSM, since it shows how you can trim leading and trailing whitespace in user-supplied content. :tup: