A
A
Alex Blinov2019-05-24 16:51:24
PHP
Alex Blinov, 2019-05-24 16:51:24

How to make a photo upload anywhere in the text in a textarea?

How can I make sure that when uploading an image to the site, an img tag with a link to this image is inserted into the textarea, as it is presented on the toaster? Throw some lesson or code. Thank you.
5ce7f673a1466360286254.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yusif Zourab, 2019-05-26
@iLegion

I can assume that you need to "determine" the location of the mouse cursor in the text field.

function getCursorPosition( ctrl ) {
        var CaretPos = 0;
        if ( document.selection ) {
            ctrl.focus ();
            var Sel = document.selection.createRange();
            Sel.moveStart ('character', -ctrl.value.length);
            CaretPos = Sel.text.length;
        } else if ( ctrl.selectionStart || ctrl.selectionStart == '0' ) {
            CaretPos = ctrl.selectionStart;
        }
        return CaretPos;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question