1

I want to replace all space and newline in a textarea with a symbol.

In my html, I have a textarea as below:

<textarea name="messageToPost"  wrap="hard" id="messageToPost" class="form-control"
rows="5" placeholder="Your post description here"></textarea>

Then, I added Javascript to get the value of the text area.

I use this code to get the value of the textarea : $("#messageToPost").val()

Now, Lets get back on the browser, I typed the text below exactly in the textarea:

Test
New Line 
Again New Line

In my javascript, when I use Inpect element in chrome, I get this value

Test↵New line ↵Again New Line

I don't know why I get this symbol ↵. I tried to use function replace to replace the ↵ symbol but in vain.

Also I try to replace it with /\s+/g.

What I want to do is, replace all spaces in my textarea value using javascript with '%20' and new line with '%0A'

Umeir Hussy
  • 61
  • 1
  • 10

0 Answers0