0

I have a problem with a textarea and the focus in IE. I have a click handler on the textarea to add a'n value. This works perfect in Firefox and Chrome, but in IE it seems to work, but then the focus goes to the left top. How can i fix this.

This is my code to edit the textarea:

$(".js-feedback").click(function(){
    var v = $(this).val();
    $(this).val(v + ((v == '') ? '' : "\n\n") + "Periode 1: ");

    return false;
});

Regards, Michel

Cerbrus
  • 70,800
  • 18
  • 132
  • 147

1 Answers1

0

Found a way.

    <textarea id="myTextarea" style="width: 98%; margin: 0px; height: 53px;" name="data[feedback][1]" class="js-feedback" placeholder="Hier uw opmerkingen..." autocomplete="off">Periode 0: Hier uw tekst
    </textarea>

    <script type="text/javascript">

        $(".js-feedback").click(function(){
            var v = $(this).val();
            if($.browser.msie){
                var htmElement = document.getElementById('myTextarea');
                htmElement.setSelectionRange( v.length, v.length );
            }
            else{
                $(this).val(v + ((v == '') ? '' : "\n\n") + "Periode 1: ");
            }
            return false;
        });
    </script>

Make sure you declared

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

also

Akhil Sekharan
  • 12,467
  • 7
  • 40
  • 57
  • Thanks, I ended up with using this code for the selection: http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area (the code of Mark). – Michel Bardelmeijer Nov 26 '12 at 10:50