how to show an auto suggestion div near the caret position in a content-editable div
Asked Answered
A

0

1

I have a content-editable div and I am trying to show an auto-suggestion near to my caret positon when i type a character.


i am looking for something like this.. but the below code is not working

        var editor  = document.getElementById('myDiv');
        var t=$(editor).offset().top;
        var l=$(editor).offset().left;
        var caretPosition = getCaretPosition(editor);
        var autoSuggestionDiv = document.getElementById('divResult');
        autoSuggestionDiv.style.top = t + caretPosition + "px";
        autoSuggestionDiv.style.left = l + caretPosition + 20 + "px";
        var inputSearch = getCharacterPrecedingCaret(editor);
        var dataString = 'searchword='+ inputSearch;
        if(inputSearch!='')
        {
            $.ajax({
            type: "POST",
            url: "Search.aspx",
            data: dataString,
            cache: false,
            success: function(html)
            {
            $("#divResult").html(html).show();
            }
            });
        }
Amoreta answered 1/3, 2013 at 14:9 Comment(1)
What isn't working about it? Maybe a screenshot would help here. Lets see your HTML and CSS while you are at it to...Uzziel

© 2022 - 2024 — McMap. All rights reserved.