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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:10:28+00:00 2026-05-24T06:10:28+00:00

I need to disable the movement of the cursor during auto-complete selection. I have

  • 0

I need to disable the movement of the cursor during auto-complete selection. I have a contentEditable div as the search bar for friends. when I type any letters an auto-complete suggestions appear underneath the search bar. During a selection of the auto-complete suggestions, I need to use the arrow keys to select. But this will also move the cursor on the search bar and it will also disable any current selection in the search bar. Can I somehow disable the movement of cursor for some specific buttons/keys on the keyboard in javascript?

Note:

  • Setting the cursor at the last position is not a solution for me.
  • I want to disable left-, right-, up-, down arrow key and also carriage return key
  • 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-24T06:10:28+00:00Added an answer on May 24, 2026 at 6:10 am

    You can call preventDefault() on keydown events that have a keycode corresponding to an arrow key or the return key. This will prevent the cursor from moving.

    The event.keyCode property will be equal to the following during a keydown event:

    • 37: Left
    • 38: Up
    • 39: Right
    • 40: Down
    • 13: Return

    So, you can attach an event listener to your div and cancel these events if there is an auto-complete suggestion active:

    var autoCompleteOn = false; //Set this flag in an auto-complete handler
    yourDiv.addEventListener("keydown",function(e){
                           //v------all arrow keys------------v     v---Return----v
      if(autoCompleteOn && ((e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13)){
        e.preventDefault();
        return false;
      }
    }, false);
    

    Note: I used addEventListener for simplicity, but for compatibility, you will have to use attachEvent or onkeydown also.

    Example jsFiddle.

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

Sidebar

Related Questions

I have a link I need to disable until a selection is made from
I need to disable slickgrid horizontal scrollbar. I have only one column and have
OK, I have two HTML select elements and a button. I need to disable
I need to disable the Mouse Clicks, Mouse movement and Keyboard Inputs for a
I need to disable the Mouse Clicks, Mouse movement for a specific windows for
I have an ajax controltoolkit reorderlist within an asp.net application. I need to disable
I need to disable this entire script until the animation is complete so it
i need to disable automatic url encoding in flash as2 because i have URL
I need to disable/enable a.href links based on checkboxes being checked. I have a
I have a Textbox where I need to disable or enable that on some

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.