The BBCode editor allows you to select specific text from a textarea, have that text inserted into an Input field, and then add a URL string back to the textarea.
This code can be used on forum-style websites, making it easy to add URLs to your visitors' posts.
Origins
- September 02, 2010 - Originally posted and shared with the Coding Source Community.
- June 20, 2012 - Updated form elements and code
- October 31, 2022 - Updated with selected text in Textarea.
Original code source to Selected text (javascriptkit.com«)
To work with an [Input] field instead of DIV, code provided by: Michel Plungjan«
- Wednesday, February 3, 2026 10:32 PM EST - I had to change the document.myform.txta -to- document.myform.code
It used to work with the name, but now it only works with the ID. Strange.
- When viewing the Code Example. Please follow the instructions located at the top of the Code Editor.
For the Insertion to work, you will first need to
Click inside this area, and press a key (Spacebar is the preferred method)
This will activate the Form and make it work.