Car Amey Lheyah
Sunday, January 15, 2012
Set focus after last character textarea
I have tried many solutions from
this discussion
but only 1 of them is working for me. Here is the codes :
<script type="text/javascript">$("textarea#messageposting").focus(function () { var val = this.value; var $this = $(this); $this.val(""); setTimeout(function () { //1 millisecond $this.val(val); }, 1);});$(function() { $("textarea#messageposting").focus();});</script><textarea><?php echo $my_note_db; ?></textarea>
But above codes is not working on IE7!!! So I find other codes and
here it is
:
<script type="text/javascript">function moveCaretToEnd(el) { if (typeof el.selectionStart == "number") { el.selectionStart = el.selectionEnd = el.value.length; } else if (typeof el.createTextRange != "undefined") { el.focus(); var range = el.createTextRange(); range.collapse(false); range.select(); }}var textarea = document.getElementById("messageposting");textarea.onfocus = function() { moveCaretToEnd(textarea); // Work around Chrome's little problem window.setTimeout(function() { moveCaretToEnd(textarea); }, 1);};</script><textarea id="test">Something</textarea>
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment