1

I am using the following example code here: http://jsbin.com/ujuse

It uses the jQuery JavaScript Library.

How can I change it so that when you select a tick box, the comma is replaced with a new line instead? I need the text area to display:

one_name

one_name1

one_name2

Not as it does at the moment:

one_name,one_name1,one_name2

If anyone could help that would be brilliant as I have tried to download and edit the jQuery JavaScript Library myself with no success.

1 Answer 1

3

You can use .join(), like this:

$('#t').val(allVals.join('\n'))

You can test it here. What's happening currently is since you're passing in an array to a string property, it's basically calling .toString(), which has the same effect as .join(','), you can use a delimiter of your choice though, like newline in the code above.

1
  • This is perfect! Thank you very much Nick.
    – David
    Dec 12, 2010 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.