Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:57:37+00:00 2026-06-09T11:57:37+00:00

I have a textbox that when I put on focus I want the cursor

  • 0

I have a textbox that when I put on focus I want the cursor to goto the end of the textbox.

The solution that keeps coming up is just

this.value = this.value

I have tried this with a simple method onclick:

function InputClicked(element) {
    element.className = "inputfocused";
    element.value = element.value;
}

but the strange this with this, it seems to goto the end and then jump to the start of the textbox.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:57:39+00:00Added an answer on June 9, 2026 at 11:57 am

    You have to focus element AND set caret position

    This JSFiddle shows you how it works. jQuery has been used for simplicity in this example, but it can be completely omitted if one desires so. setSelectionRange function is a DOM function anyway.

    In general it does this:

    input.focus();
    input.setSelectionRange(inputValueLength, inputValueLength);
    

    Obtaining input and its value length can be obtained using DOM functionality or using library functions (as in jQuery).

    Do we need input value length?

    I haven’t tested in other browsers but running in Chrome it allows to set a larger than actual position and caret will be positioned at the end. So something like:

    input.setSelectionRange(1000,1000);
    

    will work as expected (provided your text is shorter than 1000 characters. 🙂

    Note: This function isn’t supported in IE8 and older. All latest versions of most used browsers support it. For older versions of IE resort to text ranges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code that put the value of a textbox field in the
I have a textbox that when you put focus into it, it drops down
I have a textbox (I usually call it like this: document.forms[0].text.value ) that has
I have a textbox that gets a decimal value say 10500.00 the problem is
I have a javascript code for textbox that will put commas on in digits
I have just put some css on a textbox : #TxtBoxDescription { height: 30px;
I have created one form.In that form,it put one textbox.That text box should take
I have a disabled TextBox that I am editing the value of on the
I have a textbox that I am trimming the value of server side in
I have a textbox that I would like for only numbers. But if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.