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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:00:45+00:00 2026-05-25T11:00:45+00:00

At first, I thought this should be very easy. Just use $(selector).val() to get

  • 0

At first, I thought this should be very easy. Just use $(selector).val() to get the value.
However, I got a lot of difficulties.

Allow me to make an example.

Assume that I have two text boxes, and they are attached to jQuery’s AutoComplete plugin.

When I click on the first textbox, I make ajax call, when success, I bind the returned data into that clicked textbox, and a hiddenField, which is used to hold the returned ID.

The whole progress is easy, I make the ajax call and goes successful. The hiddenField now has some returned value.

When I create a second autocomplete event, and for this one, I am trying to read the value from the hidden box.

This time, failed. Not because of the ajax call, but because the value is null…

I am confused. Because the hiddenField does have some value there. But why I cannot read it easily?

Here is some codes I have

function DepartCityAutoComplete() {
$("#txtDeparture").autocomplete({
    minLength: 3,
    source:
            function (request, response) {
                $.ajax({
                    type: "POST",
                    url: "/AjaxDataServices.asmx/DepartCityAutoComplete",
                    data: '{"keyword":"' + request.term + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return { value: item.CityName + ", " + item.StateShortName, id: item.CityID }
                        }))
                    },
                    error: function () {
                        alert("An unexpected error has occurred during processing.");
                    }
                });
            },
    select: function (event, ui) {
        $("#txtDeparture").val(ui.item.value);
        $("#hiddenDepartCityID").val(ui.item.id);
    }
});

}

function DestCityAutoComplete() {

var departCityID = $("hiddenDepartCityID").val();

$("#txtDestination").autocomplete({
    minLength: 3,
    source:
            function (request, response) {
                $.ajax({
                    type: "POST",
                    url: "/AjaxDataServices.asmx/DestCityAutoComplete",
                    data: '{"keyword":"' + request.term + '","id":"' + departCityID + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return { value: item.CityName + ", " + item.StateShortName, id: item.CityID }
                        }))
                    },
                    error: function () {
                        alert("An unexpected error has occurred during processing.");
                    }
                });
            },
    select: function (event, ui) {
        $("#txtDestination").val(ui.item.value);
        $("#hiddenReturnCityID").val(ui.item.id);
    }
});

}

Can anyone give me any suggestion? Thank you very much.

Here is my guess

It is because of the $(document).ready(function ()

I have the following code:

$(document).ready(function () {
DepartCityAutoComplete();
DestCityAutoComplete();

});

So these two functions are inited when the page is loaded.
Even though the first autoComplete function assigns some value into the hiddenField, the web browser doesn’t know it.
Please correct me if I am wrong. Thanks

  • 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-05-25T11:00:45+00:00Added an answer on May 25, 2026 at 11:00 am
     var departCityID = $("hiddenDepartCityID").val();
    

    shouldn’t this be

     var departCityID = $("#hiddenDepartCityID").val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I very rarely meet any other programmers! My thought when I first saw the
At first I thought something like: var aName=getAllSomethings(); Is very unreadable, and so I'll
First, let's get the security considerations out of the way. I'm using simple authentication
First off, there's a bit of background to this issue available on my blog:
First let me say that I really feel directionless on this question. I am
Good morning, all. This is my first question on stackoverflow, so hopefully this isn't
I'm a novice iphone developer, and just completed my first iphone app. After provisioning
This is not properly a question but something more like a thought I had
I have thought of creating my first database application for one of my projects
this seems like very simple maths but somehow, my brain cant think ... i

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.