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 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 know this might sound easy. I thought about using the first dot(.) which
Okay at first I thought this would be pretty straightforward. But I can't think
This is probably a very easy question, but I never really did web... so
I want everything to be redirected to index.php, so I thought this should work:
WHY?! ... Maybe that's your first thought when reading the headline of this topic.
(Since this is my first SO question, let me just say I hope it's
My title sums this up pretty well. My first though it to provide a
This is my first time on StackOverflow though I read Coding Horror quite often.
though I have visited this site many times, this is my first question. After
here's the main code at first I thought is was the message box but

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.