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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:13:20+00:00 2026-06-04T05:13:20+00:00

I have text input, and when I focusing on it – first ‘.option’ of

  • 0

I have text input, and when I focusing on it – first ‘.option’ of ‘#number_list’ become ‘.selected’. I want to create a feature – when Up or Down key on keybord pressed than next or prev element of ‘number_list’ granding ‘selected’ class and current element loosing this class.

<input type="text" name="number" id="number" maxlength="30" />

<div id="number_list">
  <div class='option selected'>aaa</div>
  <div class='option'>bbb</div>
  <div class='option'>ccc</div>
</div>

http://jsfiddle.net/YNyEr/

I was trying to create array of ‘.option’ elements and get current element by index, but I don’t find any way to do this. So how can it be done? Also I’m using jQuery 1.5.1.

  • 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-04T05:13:22+00:00Added an answer on June 4, 2026 at 5:13 am

    How about this quick-and-dirty implementation: http://jsfiddle.net/zerkms/YNyEr/2/

    var $input = $('#some_number'),
        current_index = $('.selected').index(),
        $number_list = $('#number_list'),
        $options = $number_list.find('.option'),
        items_total = $options.length;
    
    $input.val(current_index);
    
    $input.bind('keyup', function(e) {
        if (e.keyCode == 40) {
            if (current_index + 1 < items_total) {
                current_index++;
                change_selection();
            }
        } else if (e.keyCode == 38) {
            if (current_index > 0) {
                current_index--;
                change_selection();
            }
        }
    });
    
    function change_selection()
    {
        $options.removeClass('selected');
        $options.eq(current_index).addClass('selected');
        $input.val(current_index);
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text input field like text box or text area. I want
Im doing something quite specific where I have a text input, I want to
So I have this text input in a form, and I want to update
I have a text input where people type and send text. I don't want
I have the following markup: <select style=display:none> <option value='1'>1</option> <option vlaue='2'>2</option> </select> <input type=text
I have text input boxes. There is validation for each of the boxes using
I have text input element and an event is fired on blur event and
I just wanted to ask. I have text input to allow users to type
I'm working with jquery. And i have text input in a form, i would
I have a text input : <input type=text onkeydown=processText(this) /> I have a processing

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.