473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set cursor position to the end of a text field ?

2 New Member
Hi,

I just saw the following thread:
http://bytes.com/topic/javascript/answers/157703-set-cursor-position-end-text-field

The question seems to be answered, but I don't know how to include the suggested code into my form embed code so the cursor be placed at the end of the default value:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5.   <script src="http://code.jquery.com/jquery-latest.js"></script>
  6.   <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
  7.  
  8.   <script>
  9.   $(document).ready(function(){
  10. $("#site").focus(function(){
  11.     if( this.value == this.defaultValue ) {
  12.         $(this).val("http://");
  13.     }
  14. });
  15.   });
  16.   </script>
  17.  
  18. </head>
  19. <body>
  20. <form action="#" method="post">
  21. <input id="name" type="text" name="name" /><br />
  22. <input id="site" type="text" name="mail" value="Website" /><br />
  23. <input type="submit" value="Send"> 
  24. </form>
  25. </body>
  26. </html>
I wonder if someone could help me with this.
Any help is appreciated!
Mike
Apr 22 '11 #1
3 1417
JKing
1,206 Recognized Expert Top Contributor
Right now you are changing the value of the site input box from "Website" to "http://" upon getting focus and the cursor is placed after "http://".

Is this not the intended functionality?
Apr 25 '11 #2
Rain Lover
2 New Member
"Is this not the intended functionality?"

Yes. But it's what you get over a focus by mouse. I want the same effect on a focus by Tab key.
Apr 25 '11 #3
JKing
1,206 Recognized Expert Top Contributor
I see, that was not previously mentioned.

I don't think this is going to be something that is built in as tabbing and then highlighting the text is normal behaviour for forms.

There maybe an existing plug-in that you can use.. Searching for "caret position" may also be helpful.
Apr 25 '11 #4

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

Similar topics

1
2014
by: supportgeek | last post by:
Greetings. Would anyone know the right direction to point me on this one? I need to read text from a Windows Application based on cursor position. And enter text based on what is read. ...
1
3246
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function...
2
27319
by: duzuike | last post by:
Hi, I can set focus on a text field. But the cursor is always stay at the beginning , how to set the cursor at the end ? Thank you.
2
4244
by: NewBob | last post by:
Since Access automatically highlights all of the text in a text control (I use it to hold data from a memo field) when the control is activated, I've added the following code to put the cursor at...
1
5069
by: Tantra Veda | last post by:
Hello C# gurus, I have a question about finding cursor position in NumericUpDown control. On my form I have a numericUpDown control with 2 decimal places. I want to increment value in the numeric...
1
2366
by: Paul | last post by:
Hi all, I am making a DirectInput application wich must report correctly the cursor position in windowed mode (it means it has to be the same as Microsoft Window´s cursor position). First of...
12
11407
by: Sculder | last post by:
Hello, I'm running into an interesting issue and I wanted to verify it was a bug with Internet Explorer 7. I have a field that has an javascript onBlur event. When you set focus to the text...
1
9159
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
We have some dumb and lazy people here, so I need help. To fix the dumb part: We have placed MaskedTextBoxes on the forms so they will stop entering the information incorrectly. Now the lazy...
0
2781
by: nagarjunt | last post by:
Hi, This is nag. I have a problem with infragistics7.1 UltraTextEditor control. I am using C# code in windows form. I have UltraTextEditor control(With multi line enabled) in my Windows...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.