I like this script but it's overloaded with stuff I don't need. And to get to the bottom of what, where and why - it may take me weeks to figure it all out. http://ckeditor.com/ckeditor_4.3_beta/samples/replacebyclass.html What I need is a simple script with the three functions: bold, italic, underline. You click on a bold button it will type bold, you click it again it closes the tag it. Etc. Can somebody suggest one? Or maybe you can just throw something together?
Hm. I have a small script that does that (and a bit more, but it can be stripped down) - lemme see... jQuery: $('.bbcodebuttons li span').click(function() { var textArea = $(this).parents('div').find('textarea'), getTag = $(this).attr('id').split('_'); textArea.wrap_selection('['+getTag[1]+']','[/'+getTag[1]+']'); }) Code (markup): HTML: <form id="info_form" method="post" action="#"> <fieldset><legend>Write article</legend> <label for="heading">Heading</label> <input type="text" name="heading" value="" id="heading"> <label for="ingress">Ingress</label> <input type="text" name="ingress" id="ingress" value=""> <label for="articletext" id="textlabel">Text</label>'; <?php bbcode_buttons('text'); ?> <textarea name="text" id="articletext"></textarea> </fieldset> <input name="info_form_submit" type="submit" value="Add article"> </form> Code (markup): one line of PHP in there - again, this is stripped down, normally the whole form would be in PHP, with error-handling etc. function for parsing the content from database function parseDBText($value) { if (!function_exists('normalize')) { function normalize($value) { // Normalize line endings // Convert all line-endings to UNIX format $value = str_replace('\r\n', '\n', $value); $value = str_replace('\r', '\n', $value); // Don't allow out-of-control blank lines $value = preg_replace('/\n{2,}/', '\n\n', $value); return $value; } } // code replacements $value = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $value); $value = preg_replace('#\[i\](.+)\[\/i]#iUs', '<i>$1</i>', $value); $value = preg_replace('#\[u\](.+)\[\/u]#iUs', '<u>$1</u>', $value); return($value); } PHP: The function for displaying the buttons: function bbcode_buttons($name) { global $page; $buttons = array( 1=>array(1=>'b',2=>'bold',3=>'b',4=>'boldt'), 2=>array(1=>'u',2=>'underline',3=>'_',4=>'underlined'), 3=>array(1=>'i',2=>'italic',3=>'i',4=>'italic'), ); echo '<ul class="bbcodebuttons">'; foreach ($buttons as $key => $value) { echo '<li> <span class="bbcode_button '.$value[2].'button" id="button_'.$value[1].'" title="Make the text '.$value[4].'"></span> </li>'; } echo '</ul>'; } PHP: That should be everything, I think. What it does is that if you mark text in the textarea, and click one of the buttons, it wraps that text with the bbcode - either [
Thank you so much. I want to avoid using the DB for this. Just want something in query or javascript. I did find something that is similar to what I need, but it does some funny things in IE6-8. Once I fix that I'll be alright.
No need to use the DB, just depends on what you need the input to do. No problem parsing it in javascript either, if that's what you want. But what is the input for? I'm assuming the content they're inputting is stored somewhere?