Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to get selected by the user text

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33087
    scofield
    Member

    I need to get a selected text from textarea

    #73332
    Chris Coyier
    Keymaster
    #73333
    scofield
    Member

    Thx, but I already find a solution for my problem.

    Code:


    function InsertBBCode() {
    if(document.getSelection) {
    area_val = area.value.substring(0,area.selectionStart) + first_bb_arr +
    area.value.substring(area.selectionStart,area.selectionEnd) +
    sec_bb_arr
    + area.value.substring(area.selectionEnd,area.value.length);
    area.value = area_val;
    } else {
    var selectedText = document.selection.createRange().text;
    if(selectedText!='') {
    var newText = first_bb_arr
    + selectedText + sec_bb_arr;
    document.selection.createRange().text = newText;
    }
    }
    }
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.