IE: move cursor to beginning of input

In text input, if the text exists, and you click to add more, the cursor automatically jumps to the beginning. This seems to only happen in IE.

I searched for this for a while and tried many examples that I found, but nothing works. Unfortunately, the input is written in jsp, which I do not control, and I think that the only reason I ran into this problem is because there is some kind of javascript there.

<input type="text" id="simpleSearchString" class="text" onfocus="javascript:this.value=this.value.replace(/^\s+|\s+$/g,'')" onblur="javascript:this.value=this.value.replace(/^\s+|\s+$/g,'')" value="" maxlength="255" name="searchCriteria.simpleSearchString">

All I want to do is delete this jump.

I thought adding the following code would help, but it didn't seem to do anything:

jQuery("input#simpleSearchString").focus();

I am not 100% sure what the developer is trying to achieve with "javascript: this ... etc.", But maybe I could find a way to remove it.

+5
1

;

var el = $("#simpleSearchString");
el[0].onfocus = el[0].onblur = null;

$(el).on("focus blur", function(e) {
    this.value = $.trim(this.value);    
    if ((e.type === "focus") && this.createTextRange) {
        var r = this.createTextRange();
        r.moveStart("character", this.value.length);
        r.select();
    }
});

(, IE, )

+2

All Articles