Solved

Move cursor to the end of the text field

Posted on 2006-07-06
8
1,984 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
ID: 17050628


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
ID: 17050783
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
ID: 17051231
var range = document.all["message_content"].createTextRange();
range.collapse(true);
range.select();

worked for me :)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Assisted Solution

by:Preece
Preece earned 150 total points
ID: 17051458
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
 
LVL 75

Expert Comment

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

Expert Comment

by:Preece
ID: 17054991
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
ID: 17055018
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
ID: 17108313
awesome guys, thanks for the help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

828 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