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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:23:54+00:00 2026-06-15T14:23:54+00:00

I have a autocomplete ui in which there is a pre defined User list

  • 0

I have a autocomplete ui in which there is a pre defined User list as source.
When a user selects a user from the list, it’s id is saved in a hidden field. Up to here it is fine. Now, If the user writes a user name that is not in the autocomplete list then I need to change the value of hidden field to 0 and do other tasks. But i am not able to do this…

I tried using the .change event, but its not working.
Here is the code.

$.ajax({
                type: "POST",
                url: "CHService.asmx/GetClient",
                dataType: "json",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    $('#txtName').autocomplete({
                        minLength: 0,
                        source: function (req, responseFn) {
                            var re = $.ui.autocomplete.escapeRegex(req.term);
                            var matcher = new RegExp("^" + re, "i");
                            var a = $.grep(data.d, function (item, index) {
                                return matcher.test(item.value);
                            });
                            responseFn(a);
                        }, //Searches user input with first letter of ...//data.d
                        select: function (event, ui) {
                            $('#txtName').val(ui.item.value);
                            $('#HFuser').val(ui.item.Name);

                            alert('Select' + ui.item.Name);
                            //return false;
                        },
                        change: function (event, ui) {
                            alert('Change' + ui.item.Name);
                            if (ui.item == null) {
                                $('#HFuser').val(0);


                                //return false;
                            }
                        }
                    });

So, How Basically I need is to, Set UserId when user selects the value from autocomplete, or set userid=0 when user inputs new value.

UPDATE

Forgot to add, the .change event doesn’t work because, every time the value of ui.item==null is true and the alert gave exception due to it.

  • 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-15T14:23:56+00:00Added an answer on June 15, 2026 at 2:23 pm

    Guess what, Little bit of tweaking, and I did it myself with some help from friend.

    here is the code. It is on the .change event.

                            var found = false;
                            for (var i = 0; i < data.d.length; i++) {
                                if ($("#txtName").val() == data.d[i].value) {
                                    found = true;
                                    break;
                                }
                            }
                            if (found == false) {
                                $('#HFUserID').val(0);
    
    
                            }
    

    I did was searched through my data one by one, and when not found cleared the User id.

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

Sidebar

Related Questions

I have a jQuery autocomplete field which gets results from Amazon's autocomplete, as you
i have a textinput field which has autoComplete, i populate its dataprovider from a
I have an autocomplete field where user can enter lastname firstname middlename in the
I have a form field which uses Jorn Zaefferer's autocomplete jQuery plugin. If i
I've got an input field, which's using the jQuery autocomplete method. The user starts
I have a activity which has a button and 2 autocomplete widget. for the
I have used autocomplete in jQuery from this link . In the normal browser
I have a jQuery Autocomplete field on an ASP.Net Webform and everything has been
I have an jQuery.autocomplete field presenting a limited range of decimal numbers. Ex: var
I have an autocomplete which does a query to DB....when doing a click on

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.