471,851 Members | 1,246 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,851 software developers and data experts.

How to preserve cursor position

i have function to make character in lowercase if a text is in uppercase

Expand|Select|Wrap|Line Numbers
  1.    function upperCase(x)
  2.     {   
  3.         try
  4.         {
  5.             var y=document.getElementById(x).value;
  6.             document.getElementById(x).value=y.toLowerCase();
  7.         }
  8.         catch(Error)
  9.         {
  10.         }
  11.     }

i am calling
Expand|Select|Wrap|Line Numbers
  1. <asp:TextBox ID="txtUrl" Width="450px" runat="server" Wrap="true" onkeyup="upperCase(this.id)" TextMode="MultiLine"></asp:TextBox>

but whenever i type anything withing typed text for eg. if the textbox already have string "texttexttext" n if i try to modify the middle character then on upperCase function call the the function male the character to lowercase in then cursor position goes to end of the text... so i am not able to type anything in the middle... so what is the option to preserve the cursor position at it is which was befor..
Mar 17 '09 #1
2 2274
8,658 Expert Mod 8TB
the only solution on my mind is changing the event (onchange, maybe onblur). the reason (I think) for the behaviour is that the value becomes re-written (well first deleted). maybe someone know how to position the cursor in a string.....
Mar 17 '09 #2
16,027 Expert Mod 8TB
That's what I would suggest. However, if you insist on using onkeyup, have a play with this (taken from this thread).
Mar 17 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Steve | last post: by
1 post views Thread by Tantra Veda | last post: by
1 post views Thread by Paul | last post: by
3 posts views Thread by Al-Burak | last post: by
4 posts views Thread by Brandon McCombs | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.