Clear the HiddenField if the AutoCompleteExtender does not return any results

Hey, I'm trying to figure out how to reset a HiddenField's value in case the AutoCompleteExtender doesn't return any results (specifically when the user searches for something that isn't on the list/database). This is the current JS code I have:

function handleAutoCompleteSelection(source, eventArgs) {
    var hiddenField = document.getElementById(source.get_id() + '_hidden');
    hiddenField.value = eventArgs.get_value();
}

Is there a way to modify this to check if the list is null? At the moment, it just keeps the previous value. Any suggestions would be appreciated.

Thank you!

Answer №1

I experimented with assigning both null and an empty array to the hiddenInput's value, and found that both methods function correctly. Can you please display the value of assocHiddenField.value?

<button onclick="resetHiddenInputValue();"> Reset hidden input! </button>
    <script type="text/javascript">
        function resetHiddenInputValue() {
            var hiddenInput = document.getElementById("hiddenInputId");

            alert('The value of the hidden input before the action:' + hiddenInput.value);
            var searchResult = null;
            // var searchResult = new Array(); 
            hiddenInput.value = searchResult;
            alert('The value of the hidden input after the action:' + hiddenInput.value);
        }
    </script>
<input type="hidden" value="hiddenvalue1" id="hiddenInputId" />

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

Loading Data Using AJAX with JSON on Button Press - Dealing with Array Problems

I am trying to understand how to specifically select JSON objects when a line item meets certain variable criteria that is passed when a button is clicked. Currently, I have it working but the output displays as [object],[object]. I suspect this is happeni ...

Validating the accuracy of Membership.GeneratePassword

I've encountered an issue when using Membership.GeneratePassword() to create random passwords. Sometimes the generated password does not meet the required validation criteria, especially if a user can input their own password. My goal is to ensure th ...

Delete the first and last two entries in the json dataset

data:[ { user: "2016-04-14", avg_: "13", new: "32511.20" }, { user: "2016-04-21", avg_: "32", new: "32779.17" }, { user: "2016-04-22", avg_: "32", new: "32898.40" }, { user: "2016-04-23", avg_: "32", new: "32903.11" }, { user: "2016-04-24", avg_: ...

Issues with the functionality of AJAX response values

I have been attempting to enhance a feed by adding new content when a user reaches the bottom of the page, but I am encountering issues with retrieving the content. Below is the jQuery/Javascript code I am using: $(window).scroll(function(){ if($( ...

Refreshing MVC Partial View

Currently, I am working with a partial view of a visualization (d3 partition). The data and details are populated into the partial view through a .js file that is updated by a C# backend fetching data from a SQL database and formatting it accordingly. My ...

Utilizing jQuery to efficiently chunk JSON data through AJAX calls

Is there a way to efficiently handle the retrieval of large amounts of JSON data through an ajax request? I am looking for a jQuery or JavaScript function that can assist with "chunking" the data. For example, I would like the ability to continuously rece ...

"Encountering an undefined error when making an AngularJS $http post request and receiving a

I am working on retrieving a specific value from the server side by passing a variable from the front-end (AngularJS javascript) to the backend (PHP) using $http. Once the server side (PHP) receives the value from the front-end, it executes an SQL query to ...

Using JQuery to enable the movement of divs on a screen through clicking and dragging, without the use of

Recently, I've been experimenting with a small project involving draggable divs. However, the code I've written doesn't seem to be functioning properly, causing JQuery to become unresponsive. Is there an alternative method that is simple an ...

What is the best way to transfer a property-handling function to a container?

One of the main classes in my codebase is the ParentComponent export class ParentComponent extends React.Component<IParentComponentProps, any> { constructor(props: IParentComponent Props) { super(props); this.state = { shouldResetFoc ...

Storing the result of parsing JSON data into a global variable

$(function() { var countFromData = 0; getReminder(); alert(countFromData); }); function getReminder() { $.getJSON("<?=base_url()?>home/leavereminder", {}, function(data) { ...

Assign an AJAX call to retrieve data from a MySQL table and store it in a

In my database, I have a table that includes fields for 'user_name' and 'user_round'. My goal is to set the 'user_round' field to match the value of a JavaScript variable called 'Level'. However, when I run my code, ...

Enhance the performance of ASP.NET application on mobile browsers like IPhone and Android for optimal user experience

Working on an ASP.NET application (not MVC) and looking to optimize it for IPhone and Android browsers. Have a few questions: Is there a way to detect IPhone/Android when users access the site? Any tips or pitfalls to be aware of when developing ASP.NET ...

Concealing and revealing information with jQuery and AJAX

Need help hiding a Message and displaying an alert message after 5 seconds, but it's not working. What I want is for the Message to be hidden and show an alert message 5 seconds after clicking submit. <script> $(document).ready(function () { ...

"Php makes it easy to organize seating arrangements with drag-and-drop functionality

We are currently in the process of developing a website dedicated to bus services and booking tickets. Our main goal is to allow the administrator to easily create and modify seating arrangements through drag-and-drop functionality, including the ability t ...

Exploring the concept of $http/$q/promise in Angular

I am struggling to understand when $q/$http should trigger the onReject block. For example, if I have a simple call like this: $http.get('/users') .then(function(res) { return res.data; }, function(err) { console.log(err); }); If ...

How to monitor and respond to HTML modifications in a child component from a parent component in Angular framework

In the setup I have, there is a main component known as @Component({ selector: 'parent-comp' template: '<child-comp [inputData]="responseData"></child-comp> }) export class ChildComponent { public responseData: any; ...

Sending data to another page in React Native can be achieved by passing the values as parameters

I am currently working on passing values from one page to another using navigation. I have attempted the following code: this.props.navigation.navigate('welcome', {JSON_ListView_Clicked_Item:this.state.email,})) in the parent class where I am s ...

What is the best way to extract every nth digit from a number using a given reference point?

The subject of the title may cause confusion, so let me clarify my goal. With values of n = 51 and m = 24, I aim to achieve this result: [ {start:0, end:24}, {start:24, end:48}, {start:48, end:51} ] Currently, I have made progress on this ...

The Angular service/value is failing to retrieve the updated variable from the $(document).ready() function

Currently, I'm facing an issue with my Angular service/value. It seems to be grabbing the original variable instead of the new one that is supposed to be inside $(document).ready(). Here's the relevant code snippet: var app = angular.module("app ...

An issue has been encountered in the code during the installation of react.js

node:internal/modules/cjs/loader:1148 throw err; ^ Error: Module 'C:\Users\hp\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js' could not be found. at Module._resolveFilename (node:internal ...