iShaun Posted September 9, 2008 Share Posted September 9, 2008 Hi, I am making some PHP Software and I am absoloutly horrible with JavaScript. Can someone point me in the direction of a good bb code editor? Keep in mind i DO NOT WANT A WYSIWYG EDITOR! Thats all can find tutorials on. Anyways, could someone give me a basic idea on how to highlight some text, hit a button, and have TEXT entered please? much appreciated. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 10, 2008 Share Posted September 10, 2008 Try something like this: HTML: <textarea name="my_area" id="my-area" cols="60" rows="20"></textarea><br /> <input type="button" name="selection" value="Bold" onclick="makeBold('my-area');" /> JavaScript: function makeBold(id) { var el = document.getElementById(id); if (!el.selectionStart) { if (document.selection.createRange().parentElement().tagName != 'TEXTAREA') { el.focus(); return false; } var r = document.selection.createRange().text; document.selection.createRange().text = '<b>' + r + '</b>'; } else { var txt = el.value; var before = txt.substring(0, el.selectionStart); var after = txt.substring(el.selectionEnd); var selection = txt.substring(el.selectionStart, el.selectionEnd); el.value = before + '[b]' + selection + '[/b]' + after; } el.focus(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.