Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i want to handle the cursor position when the focus comes on textbox control.like if there are 4 words in textbox then when i use
setfocus(ctrl).the cursor should be placed at the end of the 4rth word in textbox.can any body help me...!!.plz note this is a web application
Posted
Updated 2-Feb-12 23:38pm
v2
Comments
Rajesh Anuhya 3-Feb-12 5:38am    
Edited.
Varun Sareen 3-Feb-12 7:37am    
what is the requirement for such functionality?
mylogics 3-Feb-12 7:48am    
i am creating a live chat where the chat get updated in particular time interval but meanwhile if the user is typing a text then the cursor moves to starting of the textbox on focus...!!

hii finaaly got the solution jst called this js function on onfocus event of textbox....

JavaScript
<script type="text/javascript">
      function SetCursorToTextEnd(textControlID) {
          var text = document.getElementById(textControlID);
          if (text != null && text.value.length > 0) {
              if (text.createTextRange) {
                  var range
  = text.createTextRange(); range.moveStart('character', text.value.length); range.collapse();
                  range.select();
              } else if (text.setSelectionRange) {
                  var textLength = text.value.length;
                  text.setSelectionRange(textLength, textLength);
              }
          }
      }
  </script>
 
Share this answer
 
Comments
Member 13442522 6-Oct-17 6:41am    
Thanks it worked.
Manoj
Hi,

I think this[^] is what you are looking for...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900