The Ajax Auto Complete function encounters an issue when attempting to assign a value to the TextBox

I have a Textbox that utilizes an Ajax Autocomplete function.

The function is functioning correctly and retrieves values from the database, populating them in the TextBox as well.

However, there is a button on the page that triggers a query, fetching some value to display in a Label. This query uses the selected autocomplete value.

During debugging, I discovered that the value of the TextBox was null, causing issues. It seems that even though the value is populated in the TextBox, it is not being set properly.

Below is my code for AJAX:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });
    
    function SearchText() {
        $("#txtSearchDir").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "SearchPage.aspx/autoTagSearch",
                    data: "{'tagName':'" + document.getElementById('txtSearchDir').value + "'}",
                    dataType: "json",
                    success: function (data) {
                    response(data.d);
                    autoFocus: true
                    },
                    error: function (result) {
                    document.getElementById('txtSearchDir').value = "";
                    },
                });
            }
        });
    }

Answer №1

An effective method involves storing the chosen value in a concealed textbox on the webpage, ensuring its availability even after other events have been triggered.

To achieve this, utilize the

function autoCompleteItemSelected(source, eventArgs)
event.

(There exists an old online article that I previously used for reference and found very helpful, but unfortunately, I am unable to locate it at present.)

Extract the selected value by utilizing eventArgs.get_value(); and subsequently assign it to your hidden textbox.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with changing the selected value in JQuery?

I'm attempting to use jQuery to set the select option, but I'm encountering an issue. It is setting the value properly, but the text is not being updated. I've experimented with .prop('selected',true), .attr('selected',t ...

TeamCity Server experiences issues with WebDriver's ImplicitlyWait功能

In the process of developing functional tests with Selenium 2 framework on a Firefox 10 environment, we have encountered an issue with a special functionality: driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); We are attempting to set u ...

Implementing NPM commands in Jenkins using shell scripting

Whenever I attempt to run the "npm" command, I encounter a syntax error. Users/Shared/Jenkins/Home/workspace/projectName/npm test ^^^^ SyntaxError: Unexpected identifier This is the Jenkins Build shel ...

The module ~/assets/images/flags/undefined.png could not be found in the directory

When I use the img tag with a dynamic address filled using require, it works well in the component. However, when I try to write a test for it, an error is thrown. console.error Error: Configuration error: Could not locate module ~/assets/ima ...

Utilizing Node.js to create a REST API that allows for seamless communication with a MongoDB database through

Currently, I am developing a web application utilizing the MERN framework (MongoDB, Express, Node.js for back-end, React for front-end). One specific part of my web application requires frequent access to a collection in the MongoDB database (every 50 ms) ...

Limit entry to a webpage based on the user's category

Greetings, I have successfully implemented a login feature using C# webservice and ajax calls. However, there seems to be a security issue that I need assistance with. In my application, I have two types of users - admin and regular user. The problem arise ...

Tips for Implementing Multi-Level/Nested in Ajax Requests

I am currently developing a user-friendly web application with intuitive multi-level options that loads new content without the need to refresh the entire page. This is how my structure looks: /index.php /schools.html /colleges.html Within schools.html, ...

Get rid of any empty space in the image preview icon

Is there a way to eliminate the white space that appears when mixing landscape and portrait images? I want the images to move up and fill the space, even if they don't align perfectly. Additionally, I would like the images to resize based on the scal ...

Solving required packages in Express server

I am encountering difficulties with resolving dependencies on my express server. Below is the structure of my project: Calculator --dist ----app -------calculator.js -------server.js --node_modules --src ----app --------calculator.js --------server.js -- ...

Element with absolute positioning inside a relative parent does not interfere with other elements outside of the parent

I am currently facing a challenge with a simple dialog that is positioned absolutely in the center of the screen. Inside this dialog, there is a dropdown with a relatively positioned parent (I want the dropdown to follow its parent's position without ...

Interactive Requirement 6 UpdatePanel Requires Manual Mouse Movement for Refresh Post-Asynchronous Call

Our team is currently confined to using IE6 and unable to switch to a different browser. We've encountered an issue in our application where, after a postback occurs within our updatepanel, the browser appears to be resetting the DOM. One select box s ...

Add a npm module without type definitions

I am currently utilizing Typescript version 2.1 and facing an issue with installing an npm package called 'reactable' that lacks typings. When attempting to import the package using import * as Reactable from 'reactable', Typescript di ...

Validation in JQuery Mobile is crucial for ensuring that user input is correct before submitting a

Trying to create a login page using JQuery Mobile, I implemented validation with the jQuery validation plugin and AJAX to post the data to a PHP server code if validation is successful. However, instead of functioning as intended, the code redirects back t ...

Sending data from the client side using AJAX and PHP to the server

Struggling with using AJAX to send values over to a PHP file for updating a MySQL database on the server. However, I've encountered an issue where the values don't seem to be properly transferred to the PHP file. This is the JavaScript code I am ...

Sending data to a function that is generated dynamically within a loop

How can I ensure that the date2Handler is triggered with the corresponding date1 and date2 values from the month in which the date1 change occurred? Currently, whenever the date1 value is changed in any month, the date2Handler is called with the "month" t ...

Wondering how to change the background image dynamically with jQuery blockUI?

Check out this sample code from http://jquery.malsup.com/block/#demos which demonstrates how to use Growl in a simple way. I want to customize the style like this: div.growlUI { background: url(check48.png) no-repeat 10px 10px } div.growlUI h1, div.growl ...

TypeError: The function cannot be performed on the value of 0 in the Array.from

I encountered a peculiar error while attempting to utilize Array.from with Array.prototype.map. let fn = Array.from.bind(Array); // [Function: bound from] fn('test') // [ 't', 'e', 's', 't' ] ['test ...

Create a function that generates an HTML string and returns it to be used in JSX

As a newcomer to JSX/React, I am seeking guidance on removing inline code. I have created a function that returns the value to be displayed in the template/JSX. The function works well except when it needs to return a string along with an element like a Li ...

Achieving a single anchor link to smoothly scroll to two distinct sections within a single page using React

There is a sidebar section alongside a content section. The sidebar contains anchor links that, when clicked, make the corresponding content scroll to the top on the right-hand side. However, I also want the sidebar link that was clicked to scroll to the ...

PHP cannot be utilized within the script tag

I'm currently using JavaScript to display an error message If a user inputs incorrect information and I add the following code: <?php $_POST["usernamereg"] ?> = usernamereg; the alert function stops working. However, if I remove this code, t ...