473,569 Members | 2,836 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 1420
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
2018
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. Example:(the interface of the windows application would look something like this.)
1
3256
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function ConvertOld(myfield) { if (myfield.inchange) return;
2
27326
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
4247
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 the end. Private Sub txtCapability_GotFocus() ‘ Placed either behind the OnEnter or GotFocus Event of a control named, ' in this case,...
1
5077
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 box by 1 if my cursor is in front of the decimal point. If the cursor is after the decimal point, I want to increment the value by 0.1. How do I...
1
2381
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 all, I get Windows System Mouse Speed by using the function : SystemParametersInfo(SPI_GETMOUSESPEED, 0, &m_nMouseSpeed,0); After I am reading the...
12
11427
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 field, it launches a custom event handler to process the existing value in that text field. Well after the onBlur function has completed, the cursor...
1
9171
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 part: When our people click on a blank MaskedTextBox field, the cursor does not automatically go to the first "non-filled" mask value. For Example:...
0
2796
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 Form. A user can drag and drop a text(Usually from a tree node its name would be appended on drag and drop) in this control. Here user can put cursor...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.