Solved

Move cursor to the end of the text field

Posted on 2006-07-06
8
1,981 Views
Last Modified: 2012-06-21
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?
0
Comment
Question by:DuNuNuBatman
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility


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



0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 350 total points
Comment Utility
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
 
LVL 2

Expert Comment

by:yyyannag
Comment Utility
var range = document.all["message_content"].createTextRange();
range.collapse(true);
range.select();

worked for me :)
0
 
LVL 12

Assisted Solution

by:Preece
Preece earned 150 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Preece - could you not copy and paste the code from my suggestion and call it your own?
0
 
LVL 12

Expert Comment

by:Preece
Comment Utility
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
 
LVL 12

Expert Comment

by:Preece
Comment Utility
Here is that paq that I was referring to:

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

Cheers,
Preece
0
 

Author Comment

by:DuNuNuBatman
Comment Utility
awesome guys, thanks for the help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now