I want to create a simple button that will inject a [b][/b] into a textarea.
How can I do this?
I want to create a simple button that will inject a [b][/b] into a textarea.
How can I do this?
Your question is tagged jQuery, so I assume you're using it:
HTML:
<button id="mybutton>Bold</button>
<textarea id="mytextarea"></textarea>
JS:
$('mybutton').click(function(){
$('#mytextarea').append('[b][/b]');
});
Of course, a real BBCode implementation with the ability to surround highlighted text with [b] tags, and/or append [b] upon the first click of the button and [/b] upon the second, is another problem entirely.
Are you looking to bold the entire text area or only a segment of text with in the text area?