I've seen a few sites now that alphabetize what ever you put in their textarea I was wondering what I would have to do in order to add a button to mine that would produce that? I'm guessing the "JavaScript sort()" function, but I really don't know. All I've seen with that so far is using it to alphabetize arrays. This would be for anything entered, per line, in an open textarea. Any ideas?
Thanks for taking the time to read this.
I've seen a few sites now that alphabetize what ever you put in their textarea I was wondering what I would have to do in order to add a button to mine that would produce that? I'm guessing the "JavaScript sort()" function, but I really don't know. All I've seen with that so far is using it to alphabetize arrays. This would be for anything entered, per line, in an open textarea. Any ideas?
Thanks for taking the time to read this.
Share Improve this question edited Feb 14, 2013 at 4:12 Shurmajee 1,0474 gold badges13 silver badges35 bronze badges asked Feb 14, 2013 at 3:46 user2070685user2070685 795 bronze badges1 Answer
Reset to default 13split
the string into an array, sort it, then join
it back together:
var textarea = document.getElementById("theTextareaId"); // or whatever...
textarea.value = textarea.value.split("\n").sort().join("\n");