views:

96

answers:

2

I have a textarea and I want to replace "\n" with "," in it's value.

var valuetxtarr = $("#txtarr").val();
var valuetxtarrs = valuetxtarr.replace("/\n/g",",");
alert(valuetxtarrs);

But it don't work?Why?Where I have mistake?

+5  A: 

You just need to remove the quotes (otherwise it's looking for that string), like this:

var valuetxtarr = $("#txtarr").val();
var valuetxtarrs = valuetxtarr.replace(/\n/g,",");
alert(valuetxtarrs);​

You can give it a try here

Nick Craver
Oh ,yeah.Thanks!
lam3r4370
@lam3r4370 you should accept an answer when it is resolving your problems.
jigfox
@Jens - He can't for about 15 minutes after asking...it was a throttle set to encourage more answers a while back :)
Nick Craver
+5  A: 
var valuetxtarr = $("#txtarr").val(); 
var valuetxtarrs = valuetxtarr.replace(/\n/g,","); 
alert(valuetxtarrs);
Kai