MyBB Community Forums

Full Version: Help needed in textarea
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

As you know I managed to insert text from my popup window into the textarea in the parent window

http://community.mybboard.net/showthread.php?tid=26689

I need help now with this :

How I can get the selected text in the textarea so I can use it in the popup windw

any help will be appreciated

Thank You,
SadSad

any help !!
Hi ZiNga BuRgA

First thank you for your replay

But I have been searching google for the last 5 days with no luck, all the codes I found doesn't work with MyBB Sad

there is something to be changed in regular code so it fit to MyBB, unfortunately I'm not so good in javascripts ( in fact I know nothing about javascripts but I'm trying my best )

I tryed this but it select the whole text
var Sel = window.opener.textInput.value;

can you kindly give me the final code so I will just put it in my web
Or
direct me what to change

Thank you again and agian,
Using Firebug, and looking at the DOM of the textarea, it seems that it has selectionStart and selectionEnd properties. Dunno if IE has the same thing, but it could be possible to build something with the above.
IE does have something similar. It'd be something like this:

  if(typeof document.selection != 'undefined') {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', aTag.length + insText.length + eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }

Of course, that'd need some modifying, but it's got the basics for you.
Thank you Thank you Thank you that solved my problem

the code that worked for me
if(typeof window.opener.document.selection != 'undefined') {
    var range = window.opener.document.selection.createRange();
    var insText = range.text;
    range.text = '[mycode]' + insText + '[/mycode]';
    }

Thank you so much