Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, January 11, 2008

Auto Scrolling the Text Content

Call this function on the button click or other controls
//To auto scroll textbox

function autoScroll()
{ //alert("Auto ");
var d=document;
var ta, rng;
if(d.all){
ta=d.all["txtResult"];
if(ta && ta.createTextRange)
{
rng=ta.createTextRange();
//alert(rng);
rng.collapse(false);
rng.select();
}
}
}

getting the cursor position in the textarea javascript

getting the cursor position in the textarea by using java script



//script type="text/javascript"
function s(el){
var sel, rng, r2, i=-1;

if(typeof el.selectionStart=="number") {
i=el.selectionStart;
} else if(document.selection && el.createTextRange) {
sel=document.selection;
if(sel){
r2=sel.createRange();
rng=el.createTextRange();
rng.setEndPoint("EndToStart", r2);
i=rng.text.length;
}
} else {
el.onkeyup=null;
el.onclick=null;
}

el.form.elements["position"].value=i;
}
/script>