-1

I want to enter new line after every founded comma in my textarea.

<textarea id="update_destination" placeholder="Podpiete adresy" class="form-control"></textarea>

and there is how I fill my textarea

$("#update_destination").val(alias.destination);

alias is a object.

Now in my textarea I got something like xxx, yyy, zzz I want to have:

xxx

yyy

zzz

Defus
  • 789
  • 2
  • 12
  • 22
  • 4
    so [replace](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) comma with a new line \n – epascarello Dec 13 '18 at 14:00
  • 2
    `STRING.replace(/,/g, "\n")`. In your case, use `alias.destination.replace(/,/g, "\n")` :) – frobinsonj Dec 13 '18 at 14:02
  • @Profit great works fine – Defus Dec 13 '18 at 14:04
  • 2
    Possible duplicate of [Replacing commas in resultset with new line in jQuery](https://stackoverflow.com/questions/11018422/replacing-commas-in-resultset-with-new-line-in-jquery) – Mohammad Dec 13 '18 at 14:04

1 Answers1

0

Try this code:

$('#update_destination').val(alias.destination.split(",").join("\n"));

You can check out this fiddle for your ease

Can refer to this Stackoverflow Link for more detail about replace all occurrences of all string

Syamsoul Azrien
  • 2,534
  • 4
  • 32
  • 55