Move cursor to the end of the text field

Is there a way that I can move the cursor to the end of the text in a textbox instead of the default of overwriting what is already in there?
DuNuNuBatmanAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
IE: http://www.faqts.com/knowledge_base/view.phtml/aid/17749

However there is an exploit in unpatched IE's that will block this code in some firewalls
0
 
ZvonkoSystems architectCommented:


There is no method to direct move the cursor.
The overwrite method is only a side effect to the cursor.



0
 
yyyannagCommented:
var range = document.all["message_content"].createTextRange();
range.collapse(true);
range.select();

worked for me :)
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
PreeceConnect With a Mentor Commented:
Try this, it works with a textarea and a textbox and has been tested with IE only:

<script language="JavaScript" type="text/javascript">
<!--
function moveToEnd (el) {
 if (el.createTextRange) {
   var v = el.value;
   var r = el.createTextRange();
   r.moveStart('character', v.length);
   r.select();
 }
}

//-->
</script>


response.write "<br><br><input type=textbox size=20 onFocus='javascript:moveToEnd(this)'>"
response.write "<br><br><textarea cols=20 rows=20 onFocus='javascript:moveToEnd(this)'>test</textarea>"


Preece
0
 
Michel PlungjanIT ExpertCommented:
Preece - could you not copy and paste the code from my suggestion and call it your own?
0
 
PreeceCommented:
Hey, mplungjan.  I found that solution in another previously asked question here on EE.  The other question was actually enquiring about this cursor issue with regards to a textarea.  I then tested it with both a textarea and a textbox, it worked, then I posted my code.  

Sorry, didn't look at your link.

Sincerely,
Preece
0
 
PreeceCommented:
Here is that paq that I was referring to:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20702525.html

Cheers,
Preece
0
 
DuNuNuBatmanAuthor Commented:
awesome guys, thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.