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

  • SEARCH
  • Home
  • 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 499345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:58:34+00:00 2026-05-13T05:58:34+00:00

I’m working on a custom tokenfield based on textarea. The idea is to have

  • 0

I’m working on a custom tokenfield based on textarea. The idea is to have a textarea with div elements absolutely positioned above, so it looks like they are in text area.

It was pain so far, but I managed to do pretty much everything, except one thing.

Is it even possible in javascript to set reverse-selection? When you put a cursor somewhere in the middle of textarea, hold down shift and press left arrow a few times, you’ll get a selection. The tricky part, is that it’s not usual – it’s backwards (it’s start is to the right from the end, not like it is usually). There are placeholders in my textarea over which I display my divs (tokens). When you navigate to one of them, cursor jumps to the opposite edge of a placeholder, so it feels natural. When you hold down shift, and reach the placeholder, it jumps to the right, and it sets a new selection, so it looks like you selected the token (you can press delete, and remove selected range with token itself, which is cool). BUT it wont possibly work if you navigate from right to left, because setting a new selection would make it unreverted one:

Left-to-right selection:

abcde[start]efg[end](token)
[shift]+[right]
abcde[start]efg(token)[end]
[del]
abcde

Right-to-left selection

(token)[end]efg[start]abcde
[shift]+[left]
[start](token)abcdeefg[end] //see? it's back to normal
[shift]+[left]
[start](token)abcdeef[end]g //huh?! shift-right moves end point (unexpected)
abcde

So here’s question: Can I set a selection in textarea where start point would be greater than the end point? Simply element.setSelectionRange(right, left) does not work in firefox, any other ideas?

  • 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-13T05:58:34+00:00Added an answer on May 13, 2026 at 5:58 am

    After experimenting a bit in the Firebug console, I think it is not trivial. However, you can intercept the keypress event:

    If the user presses the left arrow, you have to extend the selection to the left yourself and return false. Then the browser’s default is not called, but the user has nevertheless the feeling of a leftwards selection.

    textarea.onkeypress = function (event) {
      if (!event){event = window.event; /* %#$! IE */ }
      if (event.shiftKey && event.keyCode == 37 /* left */) {
        event.target.selectionStart = currentSelectionStart - 1;
      }
      return false;
    };
    

    37 is the left arrow, 38 is up, 39 is right and 40 is down.

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

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, objects aren't passed by reference. References are passed by… May 13, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer Most likely you didn't include the CoreLocation framework in your… May 13, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer I changed my query so that i don't have to… May 13, 2026 at 5:14 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.