Solved

Move cursor to the end of the text field

Posted on 2006-07-06
8
1,982 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

895 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

15 Experts available now in Live!

Get 1:1 Help Now