Faqts : Computers : Programming : Shopping For You : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

53 of 132 people (40%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Can I use JavaScript to move the cursor to a certain position in a textarea (besides the 1rst pos.)?

May 26th, 2005 00:44
tomas santoro, Linda D,


function setCursorPosition(oInput,oStart,oEnd) {
   	       if( oInput.setSelectionRange ) {
    	         oInput.setSelectionRange(oStart,oEnd);
             } 
             else if( oInput.createTextRange ) {
                var range = oInput.createTextRange();
                range.collapse(true);
                range.moveEnd('character',oEnd);
                range.moveStart('character',oStart);
                range.select();
             }
       }