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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:12:44+00:00 2026-06-10T04:12:44+00:00

I have a type of input text that has to trigger a function on

  • 0

I have a type of input text that has to trigger a function on ‘keydown’. In order to identify this type of input I used an Id #autocomplete. So

$('#autocomplete').keydown(function(){
   //function autocomplete
});

The problem is that I have this input twice in the same page, so jquery searches for the first id, and ignores the second one. (I am using an old jquery version, 1.3).

I solved it using $(“input#autocomplete”) instead. It works but is it a best practice? I guess Ids have to be unique. I could use class or name instead, but both have implications to other parts of code (class to the design, name to the server part the receives form parameters).

Which would be the best solution?

  • 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-10T04:12:46+00:00Added an answer on June 10, 2026 at 4:12 am

    If you are in doubt for class or name due their affects on design and server, you can always use attributes.

    <input data-id="my-id"/>
    

    and then select it like so

    $("[data-id=my-id]")
    

    custom attributes that has data- prefix are a standard in HTML5.

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

Sidebar

Related Questions

I have this input that has text and when you click it, the text
I have a text input field that has some sample text in a light
Is it possible to change the value of an <input type=text> that has been
I have a ruby on rails application with an input text field that has
I have an expense report type form that has an input asking for mileage.
I have an input of type text , from which I have already entered
I just wanted to ask. I have text input to allow users to type
I have an INPUT element of the TEXT type and I want to perform
I have the following HTML: <input type=email id=email> I want to type text into
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',

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.