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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:29:27+00:00 2026-05-25T14:29:27+00:00

We have a few text areas that have some text the user may copy

  • 0

We have a few text areas that have some text the user may copy to their clipboard.

Without going into too much detail as it will just complicate a straightforward question:

Is it possible to detect if a textarea‘s contents are ‘selected’?


I should mention using the onclick (or other) event handlers are (ideally…) not an option.

As this text is selected by an ‘outside of the textarea’ action.

The flow is somewhat as follows:

Drop down choice is chosen -> Text in textarea is selected

Or

Textarea is clicked (onclick) -> Text in textarea is selected

I know we could use a whole bunch of event handlers to detect the state of the text in the textarea, but I was hoping there was a simpler way of doing by detecting the state of the text inside the textarea via JavaScript.

  • 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-25T14:29:27+00:00Added an answer on May 25, 2026 at 2:29 pm

    This code is taken from this question. You’ll need to adapt the code slightly, but it shows how to access the selection for both Mozilla and Internet Explorer browsers –

    function ShowSelection()
    {
      var textComponent = document.getElementById('Editor');
      var selectedText;
      // Internet Explorer version
      if (document.selection != undefined)
      {
        textComponent.focus();
        var sel = document.selection.createRange();
        selectedText = sel.text;
      }
      // Mozilla version
      else if (textComponent.selectionStart != undefined)
      {
        var startPos = textComponent.selectionStart;
        var endPos = textComponent.selectionEnd;
        selectedText = textComponent.value.substring(startPos, endPos)
      }
      alert("You selected: " + selectedText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that lets the user enter in some text. It will
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have a few functions that I'm using to draw different type of text.
I have a few areas on my site where I need to limit text
I have a scenario where I have some text, which should be user-selectable. The
I have some text that needs to be displayed in my app. The text
I have a few text boxes and buttons on my form. Lets say txtBox1
I have a few text files and I'd like to count how many times
I have problem with TinyMCE editor. I have form with few text fields and
Here's the problem -- I have a few thousand small text snippets, anywhere from

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.