How To Set The Scrollbar To Move At Last Line In Multiline Textbox?
I am using asp.net. How to set the scrollbar to move at last line in multiline textbox at client side?
Solution 1:
Set ClientIDMode="Static"
so you can reference the textarea from jQuery using its ID:
<asp:TextBoxID="myTextBox"runat="server"ClientIDMode="Static"TextMode="MultiLine"></asp:TextBox>
And add this script after jQuery script tag:
$(document).ready(function () {
$('#myTextBox').scrollTop($('#myTextBox')[0].scrollHeight - $('#myTextBox').height());
});
I was curious about compatibility so I tested it in Chrome, Firefox, Opera and IE9 and it works. :)
Here is a jsFiddle example of the solution: http://jsfiddle.net/g9KBB/
Solution 2:
possible solution with jquery (worked for me in chrome 19):
$('#wmd-input').scrollTop($('#wmd-input').height())
where wmd-input
is the id of the textarea
Solution 3:
functionf(ta_id) {
var d = document, ta, rng;
if (d.all) {
ta = d.all[ta_id];
if (ta && ta.createTextRange) {
rng = ta.createTextRange();
rng.collapse(false);
rng.select();
}
}
}
functionSetTextBox(ID) {
varTextBoxes = document.getElementById(ID.id);
if (TextBoxes != null) {
for (var i = 0; i < TextBoxes.length; i++) {
f(TextBoxes[i].id);
}
}
}
Post a Comment for "How To Set The Scrollbar To Move At Last Line In Multiline Textbox?"