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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:58:57+00:00 2026-05-16T11:58:57+00:00

Hi I want to prevent users from using the enter key unless they are

  • 0

Hi I want to prevent users from using the enter key unless they are in a specific text area on my form . I can stop the enter button being used but how can I find out which part of my form is in focus using js ? Any help would be great , thanks

  • 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-16T11:58:58+00:00Added an answer on May 16, 2026 at 11:58 am

    You can assign a global variable. With jquery:

    $('#id-of-textarea').focus(function(){textareaIsSelected = true});
    $('#id-of-textarea').blur(function(){textareaIsSelected = false});
    

    Although the use of globals is quite discouraged, it’s the fastest way and you can check for the global anywhere in your script. If you don’t use jquery you can use this shortened function:

    function addEvent(a,b,c){
        if(a.addEventListener){a.addEventListener(b,c,null)}else{a.attachEvent("on"+b,c)}
    }
    
    function toggleTextareaSelected()
    {
        textareaIsSelected = !textareaIsSelected;
    }
    
    addEvent(document.getElementById('id-of-textarea'),'focus',toggleTextareaSelected);
    addEvent(document.getElementById('id-of-textarea'),'blur',toggleTextareaSelected);
    

    EDIT (from this answer):

    So now it’s [document.activeElement] supported in the latest
    release of all major browsers
    (IE,FF,Safari,Chrome,Opera). I’d only
    use the event hack as a fallback for
    older browsers:
    if(!document.activeElement) { /* add
    event-listeners to set
    document.activeElement for older
    browsers */ }

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

Sidebar

Related Questions

I want to prevent users from running my cron job manually. Apart from using
How can I prevent users from using the backspace or delete keys in a
I want to prevent users from using webcam emulators, I have done that in
I want to prevent users from commenting on deleted threads. I've set a variable
In my studies, I have learned that if you want to prevent users from
I want a permission that will prevent people from logging in. (So, all users
Is there any way I can prevent the user from hitting the return key
We want to prevent other users from editing other users profile, still allowing a
How can I prevent users from adding new tags which don't already exist in
I'm using jQuery 1.7.2. I don't want to prevent form submission. I want to

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.