views:

46

answers:

1

Hi all,

I'm a bit new to Javascript and am trying to create a delimited string from a textarea. The problem is when passing in the textarea, it adds newlines for each row on the textarea. I need to have the entire textarea parsed into a string with a delimiter for each line (replacing the newline char). So for example, if you passed in a textarea with the following lines (which is also how it looks when using the alert function):

abcd
efgh
ijkl

It would look like: abcd-efgh-ijkl after parsing.

function submitToForm(form)
{
    var param_textarea  = form.listofplugins.value;
    var test = param_textarea.replace(/\\r?\\n/, /:/)
    alert(test);
}

Thanks a lot!

+4  A: 

You don't need the doubled backslashes; just one is fine.

var test = param_textarea.replace(/\r?\n/g, ':')

Also as you see the second param should be a string. Finally the regex should end with "g" to make it a "global" replace.

Pointy