...

View Full Version : String Question



jason_kelly
03-09-2012, 01:47 PM
Hello,

I need your help.

For one reason or another, I have a textarea with text in it, however, when I call it back and store it in var, it seems to strip all the spaces.

[ID = "COMMENTS"]
Ie. of what's in the textarea:
----------------------------------------------
Apples are red

Oranges are orange

Pears are green

Bananas are yellow


var comments = document.getElementById("comments").value

returns:
Apples are red Oranges are orange Pears are green Bananas are yellow

How could this be re-written such that the spaces in between the text aren't ignored?

Much thanks and appreciation for everyones help.

Cheers

J

ckeyrouz
03-09-2012, 02:02 PM
What do you mean by spaces are being ignored. Do you mean the line break?

Are you sure you have hit the return key from a line to another or the textarea width is small so when you are typing the whole sentence it is putting it on several lines?


I have done a small example here and it seems to be working fine?

Can you give me more details about your problem and how to reproduce?

Would be much better if you posted your code here.

DaveyErwin
03-09-2012, 02:11 PM
<body>
<textarea id="ta">
hel lo?

whasssup?
</textarea>
<div id=dsply></div>
</body>
<script type="text/javascript">
var taValue = document.getElementById("ta").value

document.getElementById("dsply").innerHTML =
taValue.split(" ").join("&nbsp;").split("\n").join("<br>");

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum