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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:11:48+00:00 2026-05-13T07:11:48+00:00

How do you find out what the user typed or pasted into a textarea?

  • 0

How do you find out what the user typed or pasted into a textarea? For example, if they typed in B (or β) at index 1, or if they pasted hello world\n at index 23. I’ve searched a fair bit but can’t find anything. Here’s what I have so far, uses jQuery:

$("textarea").keydown(function(evt){
    var index= getCaret(this); // this.selectionStart doesn't work in IE
    var key = evt.keyCode; // Wrong.
}

See this question for getCaret. The problem with event.keyCode is non-english keyboard layouts. I’m entirely stuck as far pasting is concerned.

If possible, I’d like to know the values before the textarea is changed – that is, from within the keydown event. I’m not sure if this can be done for pasting.

(Deletion is easier – detect keyCode==8 for backspace and keyCode==46 for del. If selection.length > 0, then the selection is removed; otherwise the character before or after is removed. In theory. There’s also the case of pasting on top of a selection.)

Anything that gets any part of this closer to working in any browser is greatly appreciated. That is, how do you know:

  1. the unicode string value of the typed character?
  2. when a paste occurred?
  3. what the text content of the paste is?
  • 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-13T07:11:48+00:00Added an answer on May 13, 2026 at 7:11 am

    I’m not quite sure what your ultimate goal is here, so it’s difficult to advise. However, here’s some information:

    When the user types a character, getting what they typed is easy enough using the keypress event and (assuming your event object is stored in a a variable called evt) using String.fromCharCode(evt.keyCode || evt.which).

    For pasting, things are a bit trickier. The simplest thing would be to detect the paste before it has happened, store the textarea’s value and after a very short time (using window.setTimeout) compare the new value with the old. As for detecting the paste, a lot of browsers now have the paste event: IE since version 5, Firefox since version 3 and WebKit browsers for a while (not sure exactly when), so you can use that for those browsers. As a fallback for other browsers you could detect Ctrl-V and Shift-Insert in a keydown event handler, though this is by no means foolproof since it won’t fire when the user pastes using the Edit menu or the context menu in their browser.

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

Sidebar

Related Questions

I'm trying to find out current user name for my sharepoint application. There are
Is there any way to find out if the user pressed the delete key
How do I find out which sound files the user has configured in the
How do you find out the local time of the user browsing your website
How can I find out which row in a JTable the user just clicked?
How can I find out, which keyboard layout the user of my ruby application
In Unix/Linux, how do you find out what group a given user is in
I need to find out how to format numbers as strings. My code is
How can I find out which Service Pack is installed on my copy of
I would like to find out safe ways of implementing three dimensional arrays of

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.