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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:35:54+00:00 2026-06-12T08:35:54+00:00

Okay guys , so I have this algorithm that selects an option based on

  • 0

Okay guys , so I have this algorithm that selects an option based on the keys that you press(up or down arrows).

var nr = 0;
    $(function(){
        $('#searchbox').keyup(function(e){
            var total = $('#suggest'+nr).attr("total");
            var code = (e.keyCode ? e.keyCode : e.which);
            if ( up(code) == 1 )
            {
                if (nr == 0)
                {
                        $('#suggest'+total).addClass('hlight');
                }
            }
            else
                if ( down(code) == 1 )
                {
                    $('#suggest'+nr).css({'background':'red'});;    
                }
        });

    });

But the problem is that every time I release the respective div gets selected for like a fraction of a second by changing his background color and then get back to the original background color.

How do I make it highlight the div and the css to remain applied ?
Thank you.

HTML :

<div id="search">
                <form action="home.php" method="get" name="search">
                   <input type="text" id="searchbox" name="srch" size="60" value="Search..." onFocus="if(this.value == 'Search...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Search...';}" />
                   <input type='hidden' name='q' value='<?php echo $q; ?>' />
                   <input type='hidden' name='page' value='1' />
                  <button type="submit" id="searchb"><img src="pics/lens1.jpg" alt="Submit"></button>
                </form>

                </div><!--end search-->

PHP :

echo "<p class='suggestion' id=".$char." total=".($total-1)." style='color:black;font-size:13px;margin-bottom: 7px;'>".$id.",".$strg."</p>";

CSS:

<style >
.hlight{
    background:yellow;
}
​

</style>
  • 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-06-12T08:35:55+00:00Added an answer on June 12, 2026 at 8:35 am

    Take a look at the key functions here:

    http://jsfiddle.net/Mutmatt/mQahU/

    var keyMap = {
        87: 'P1UP',
        83: 'P1DOWN',
        38: 'P2UP',
        40: 'P2DOWN'
    },
        getKey = function(key) {
            return keyMap[(key.which || key.keyCode)] || '';
        };
    
    $(document).keydown(function(event) {
            switch (getKey(event)) {
            case 'P1UP':
                event.preventDefault();
                keys['P1UP'] = true;
                break;
            case 'P1DOWN':
                event.preventDefault();
                keys['P1DOWN'] = true;
                break;
            case 'P2UP':
                event.preventDefault();
                keys['P2UP'] = true;
                break;
            case 'P2DOWN':
                event.preventDefault();
                keys['P2DOWN'] = true;
                break;
            default:
                break;
            }
        });
    
        $(document).keyup(function(event) {
            switch (getKey(event)) {
            case 'P1UP':
                event.preventDefault();
                delete keys['P1UP'];
                break;
            case 'P1DOWN':
                event.preventDefault();
                delete keys['P1DOWN'];
                break;
            case 'P2UP':
                event.preventDefault();
                delete keys['P2UP'];
                break;
            case 'P2DOWN':
                event.preventDefault();
                delete keys['P2DOWN'];
                break;
            default:
                break;
            }
        });
    

    might help?

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

Sidebar

Related Questions

Okay, I have a feeling that you guys'll be able to quickly point out
Hye guys. Okay. I have done this coding. But it seems have error. Can
Okay guys hopefully I can explain this effectively, so here goes. I have a
Okay guys, I have been scratching my head like mad over this issue and
Okay guys, I have read through all the other posts and question on jQuery
Okay, guys i have been trying to define a Stack , each node also
Okay guys, basically the problem I'm having is this. I've been assigned to write
Okay, before you guys go nuts -- this is just a small site, temporary
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.

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.