rarebit Posted May 7, 2008 Share Posted May 7, 2008 Hi, can anyone test this with IE please? (or other browsers, i've tested with FF and Opera) <script type="text/javascript"> function tester(s) { var txtbox = document.myform.post; var begin = txtbox.value.substr(0, txtbox.selectionStart); var end = txtbox.value.substr(txtbox.selectionEnd); txtbox.value = begin + s + end; document.myform.post.focus(); } </script> <a href='javascript:tester("world")'>tester</a><br> <form name='myform'> <textarea cols="64" rows="12" name="post">HELLO!</textarea> </form> Just click your cursor in the middle and click the link! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 8, 2008 Share Posted May 8, 2008 Looks good, I would just add one line to the function to make it this: function tester(s) { var txtbox = document.myform.post; var begin = txtbox.value.substr(0, txtbox.selectionStart); var end = txtbox.value.substr(txtbox.selectionEnd); txtbox.value = begin + s + end; txtbox.selectionEnd = txtbox.selectionStart = begin.length + s.length; document.myform.post.focus(); } Quote Link to comment Share on other sites More sharing options...
hassank1 Posted May 9, 2008 Share Posted May 9, 2008 is this related to adding a text to a text area ?? I want for example when an event is triggered to write something where the txt cursor in the text area is pointing .. for example like the buttons above ( B , I , ...) they add the bbcode where the cursor is pointing .. please I need a clear example thx Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 9, 2008 Author Share Posted May 9, 2008 That's what this does, but it doesn't wrap highlighted code, just replaces it or inserts it if nothing is selected. If you wanted to wrap some text, the bit you want to wrap is the difference between 'begin' and 'end'. I haven't got access to my stuff right now but i'll post it soon... 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.