3.2.0

set caret position for Input control

Alex:

I am rephrasing my previous question to a more useful generic one:

how would one set the caret position on an Input control?
Eric Juvet
February 7,
In IE you should create a text range, move it to the desired position and then call select() method of the text range. In other browsers you can manipulate the selection using selectionStart/End properties of the input element.

Here is the sample code which moves the selection to the end of the text -

obj.onControlEditStarted = function(){
    this.setTimeout(function(){
        var e = this.element().getElementsByTagName("INPUT")[0];
        if (AW.ie) {
            var r = e.createTextRange();
            r.collapse(false);
            r.select();
        }
        else {
            e.selectionStart = e.selectionEnd;
        }
    });
}
Alex (ActiveWidgets)
February 7,
Thank you very much, Alex, truly appreciate your help.

Every place that I work at as a contractor, I require them to purchase ActiveWidgets.
Eric Juvet
February 7,

This topic is archived.

See also:


Back to support forum