Insert into textarea at current cursor positon - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Insert into textarea at current cursor positon

JonathanJonathan Posts: 2,914Member
Hello,

Was wondering if anybody knew how to insert text into a text area at the position the cursor is currently at? I can append and replace a selection, but I haven't been able to find a way to insert where the cursor is.

All help greatly appreciated! :-)

Thanks,

Jonathan


###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Comments

  • BTSBTS Posts: 1Member
    [b][red]This message was edited by BTS at 2003-7-10 7:43:52[/red][/b][hr]
    I use the following script to insert text to my textareas:
    [code]function doInsert(oTag, cTag)
    {
    var obj_ta = document.form_name.textarea_name;

    if(obj_ta.isTextEdit){
    obj_ta.focus();
    var sel = document.selection;
    var rng = sel.createRange();
    rng.colapse;
    if((sel.type == "Text" || sel.type == "None") && rng != null){
    if(cTag != "")
    oTag += rng.text + cTag;

    rng.text = oTag;
    }
    }
    else{

    obj_ta.value += oTag;
    }

    obj_ta.focus();
    return true;
    }[/code]This will insert the oTag before and the cTag after the selected text in the textarea. if there's no text selected it will insert oTag+cTag at current cursor position.


  • JonathanJonathan Posts: 2,914Member
    Hi,

    It's taken me until now to try it out, but it's great. Thanks! :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.