CreateTextRange - strange behavior in IE8

I have the following problem. In a text input that works like an autocomplexer, some of the sentences it returns fade away than it does. The problem arises when you leave the field. In IE, the text cursor is placed at the end of the suggested line, so you can only see the last part of it. So I used the below code to fix it and it works under IE6, but in IE8 it doesn't work, the box is always selected and I can't select anything on the page.

My question is how to properly move the cursor to the beginning of the input field after I have left it?

$ ('# myAutocompleter'). blur (function () {
  textRange = this.createTextRange ();
  textRange.collapse (true);
  textRange.select ();
});

(The code used is written in jQuery.)

+2


source to share


3 answers


I believe that you are looking for techniques .moveStart

and .moveEnd

in the text range:

$('#myAutocompleter').blur(function(){
  textRange = this.createTextRange();
  textRange.collapse(true);
  textRange.moveEnd('character',0);
  textRange.moveStart('character',0);
  textRange.select();
});

      



(Tested in IE8)

+3


source


I'm not sure if I understand your question, but IE has its own set of methods for handling text on a page, so it therefore behaves differently.

Check out the tutorial here: http://www.quirksmode.org/dom/range_intro.html



But for compatibility: http://www.quirksmode.org/dom/w3c_range.html

If that's not your problem, try doing a mouse check or clicking on an event inside the blur and putting the selection code there? Perhaps this will cause the selection to move away from the input field before placing it where the selection is.

0


source


I had a similar situation where I wanted to see the top / bottom of something depending on things like this. I used the jQuery scrollTo plugin

).scrollTo('100%')

).scrollTo('0%')

      

EDIT 1: I am using it in this field:

<textarea cols="57" rows="2" class="cssTextarea cptEntryArea"></textarea>

      

with this code:

  $(".cptEntryArea").change(function()
        {
           $(this).scrollTo('0%');
   });

      

0


source







All Articles