I'm trying to make a simple generator that will take each line of a textarea, add a prefix and then output that data again in a textarea which can optionally be downloaded in a .txt file. Can anyone help?
Do you really need to make your own? There are already tools for that online: http://textmechanic.com/Add-Prefix-Suffix-to-Text.html
Here you go: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> HTML: function AddTags(name, prefix, suffix) { try { var textArea = document.getElementById(name).value; var i = 0; var textArray = textArea.split("\n"); if (textArray === null) { document.getElementById(name).value += prefix + suffix; } else { for (i = 0; i < textArray.length; i++) { textArray[i] = prefix + textArray[i] + suffix; } document.getElementById(name).value = textArray.join("\n"); } } catch (err) {} } Code (JavaScript): <textarea id="TextBox" cols="50" rows="20"></textarea> <button id="myButton" onclick="AddTags('TextBox', '[prefix]', '[/suffix]')">Add [p][/s]</button> HTML: If you don't need a suffix, just leave that blank. http://jsfiddle.net/chiappa/8v4kdwex/
Thanks so much, that's awesome. Any idea how it could be output in a .txt file for the visitor to download after hitting the button?