Search code examples
javascripttextautocompleteautosuggestexpand

Javascript Text Expander


I'm trying to build a really simple form to help me out typing comments (left in our systems after chatting with customers) and get something like "cci" get replaced by "customer called in".

Is this possible with javascript? I'm asking this because we're not allowed to install any software such as Texter however we are allowed to bring html/js files at work.

Hoping that my problem has been described in full I would like to thank you in advance!

PS: any snippets or links to tutorials are really appreciated!


Solution

  • Make a function which runs at regular intervals and replaces shortcuts in a textarea:

    update = function() {
        textarea.value = replace-shortcuts-in(textarea.value);
    }
    
    textarea.onkeydown = function() {
        clearTimeout(timer);
        timer = setTimeout(update, 200);
    
    }
    

    Complete working example: http://jsfiddle.net/ucsED/