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 6845043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:27:06+00:00 2026-05-27T00:27:06+00:00

I have a text area which on page load has default text of List.

  • 0

I have a text area which on page load has default text of “List”. On focus this text is removed and replaced with “-“. I would like the caret position to be after the “-“, this works in chrome, opera, FF and safari but in IE the caret initially is in the correct place, but then after a slight pause jumps to before the “-“.

Here’s the code I’ve been using:

    input.onfocus = function(){
        if(this.value == 'List') {
            this.value = '-';
        }
    }

I have tried using the onclick event as well, using tricks like this.value = this.value after the “-” is inserted but none of this works. If anyone could provide me with a work around I will be extremely grateful.

Thank-you!

edit:
Kierans answer below solved the problem, perfect! An if statement added to his code stops chrome throwing a little error:

    input.onclick = function(){
        if(this.value == 'List') {
            this.value = "-";
            if (this.createTextRange) {
                var range = this.createTextRange();
                var caretPos = this.value.length;
                range.move('character', caretPos);
                range.select();
            }
        }
    }
  • 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-05-27T00:27:07+00:00Added an answer on May 27, 2026 at 12:27 am

    I tried a simple code snippet in Firefox,Chrome and IE. Same issue i am facing in IE so that we can set the caret position with some code snippet that as follows:

    <input type="text" value="List" onfocus="changeValue(this);"/>
    function changeValue(e){
        if(e.value == "List"){
                e.value = "-";
               var range = e.createTextRange();
                var caretPos = e.value.length;
                range.move('character', caretPos);
                range.select();
        }
    }
    

    So, above code is working fine.

    For reference see the url : http://jsfiddle.net/J72xB/1/

    NOTE: Above code is tested in FireFox6,Chrome,IE9.Hope this will help you. 🙂

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

Sidebar

Related Questions

I have a page which has a rectangular area with text and icons in
I have a text area on which I would like to listen to change
I have a text area page which is launched from the previous page: $message
Is it possible to have something like global area which would be displayed in
I have a page, it has a drop down list, which contains the names
I have a page which contain a bunch of text area generated by a
Does JavaFX 2.0 supports printing? I have a text area from which I take
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I would like to have some functionality by which if I write <textarea maxlength=50></textarea>
I have a node with a text area editable with CKEditor. THis means my

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.