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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:00:00+00:00 2026-06-07T02:00:00+00:00

Im trying with jquery to advanche an auto-complete textfield. user types 3 chars the

  • 0

Im trying with jquery to advanche an auto-complete textfield.

  • user types 3 chars
  • the cities gets loaded into a drop down ( with ajax autocomplete )

Now I would like to:

  • Prevent the user from manually enter there city name but instead choose it from the drop down list. Is there a good way to do this? I have searched and searched but not found a good solution because the user at first have to be able to type a few chars in the textfield, for the autocomplete to be triggered.

My function so far wich works (it returns only city_name for now):

  $("#user_profile_attributes_city_id").autocomplete({
    source: "/data/living",
    minLength: 1,
    select: function( event, ui ) {
      $(this).val(ui.item.label);
      $(this).find("#country_id").val(ui.item.country_id);
      $(this).find("#city_id").val(ui.item.city_id);
      event.preventDefault;
    }
  })
  • 1 1 Answer
  • 1 View
  • 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-07T02:00:02+00:00Added an answer on June 7, 2026 at 2:00 am

    You can put autocomplete initially,

     <input autocomplete="off" />
    

    Actually you chould put some validation on FORM submission if the value is in a list you wanted.

     $('form#id').submit(function(){
    
    //validate
    if ($(this).val().length > 3) {
        return false;
    }
    if ( $(this).val()  is_in_list ) {
        return false;
    }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm trying to add on to the auto-complete module for jquery that is
I am trying to build an auto complete using Solr (TermsComponent) and Rails. Now
Hi I am trying to write a script in Jquery that auto selects the
I'm trying to develop a jQuery plugin to do an action when the user
I'm trying to post a Facebook profile picture into a Jquery popup window and
I'm trying out jQuery masonry animation examples, and managed to get a basic page
I'm using (or trying to) JQuery Validation with WebForms/html. I have, basically (simplifying the
I have 2 dropdown lists on my webform and using jquery trying to filter/reset
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying to use jquery to detect when the ENTER key is pressed AND

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.