How to set the cursor to the end of a input box?

C

Cylix

My function is going to set some predefined value to a input text box,
and it will focus to the inputbox and set it to the end of the value.

As the title, how to set the cursor to the end of value?

Thanks a lot!
 
S

scripts.contact

how to set the cursor to the end of value?

var i = inputElement // <<<

var len=i.value.length;
if(i.setSelectionRange)
i.setSelectionRange(len,len)
else if(i.createTextRange){
var r=i.createTextRange();
r.moveStart("character",len)
r.select()
}
i.focus()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top