Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me. In my code on button click i add some string in textbox but after adding string it looses the focus or it not appears in that textbox. i want cursor after the text in the textbox. i used formview. i used txt.focus(); but it sets at the start of the text.
Posted
Comments
Vaishali P. Patil 19-Jun-12 1:03am    
Thanks, i used this but sets cursor at the start of the text not end and i also used bellow <script type="text/javascript">
function SetCursorToTextEnd(textControlID)
{
var text = document.getElementById(textControlID);
if (text != null && text.value.length > 0)
{
if (text.createTextRange)
{
var FieldRange = text.createTextRange();
FieldRange.moveStart('character', text.value.length);
FieldRange.collapse();
FieldRange.select();
}
}
}
</script>


but it shows me error textControlID does not exist in the current context

1 solution

Doing something like this should do:
C#
txt.focus();
txt.value = txt.value;


Here, have a look at similar discussions:
Set cursor position in TextBox[^]
Javascript: How To Set Cursor to Textbox End[^]
 
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