Deactivate the ajax submission button when a key is pressed

There is a button on my Ajax form that, when clicked, displays to the user that it is currently "searching" by showing a small loading symbol while the database is being queried.

Upon clicking the submit button, it triggers a function. This function disables the button, gathers the form data, initiates the Ajax call (which is non-asynchronous meaning the code waits for the call to finish before proceeding), and then re-enables the button.

Here's an example of how it works:

function CheckForm()
{
    disableButton(document.getElementById("save"));


    ....... lots of instructions in here ........
    ....... Loops through every form el .........


    //Ajax called
    CallAjax(sUrls, sParams);

    enableButton(document.getElementById("save"));

}


function disableButton(element)
{
    try
    {
        disabledEl = element.id
        disabledElOrigTxt = element.value;
        element.value = '    Loading...'

        addClass(element, "pleaseWait");
        addClass(document.myForm.reset, "resetWait");

        element.disabled = true;
        document.myForm.reset.disabled = true;

        //return true;
    }
    catch(e)
    {
        ////SHHHHHH
    }   
} 

function enableButton(element, timer)
{
    try
    {
        if(element.value == '  Loading...')
            element.value = disabledElOrigTxt;  

        removeClass(element, "pleaseWait");
        removeClass(document.myForm.reset, "resetWait");
        element.disabled = false;
        document.myForm.reset.disabled = false;
        clearTimeout(timer);
        return true;
    }
    catch(e)
    {
         ////SHHHHHH
    }
}
// More functions...

This script runs perfectly in Mozilla and IE, however, there seems to be an issue with Chrome. Does anyone know why?

If I add an alert("hi") to the end of the disableButton() function, I can see the button change in Chrome... only when I interrupt the script with an alert. Obviously, this is not a solution.

Answer №1

Is it possible that the CallAjax() function is functioning asynchronously in Chrome?

Alternatively, could it be that Chrome is processing the function so quickly that the changes are not immediately noticeable?

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

Sending numerous web service requests from a single HTML page

My current challenge involves submitting three separate forms on a single page. I have encountered an obstacle while attempting to verify a mobile number in the first form, and then utilize that verified mobile number for final form submission. I initiall ...

Shrink Table Column Size with Bootstrap and Stylus to Optimize Space Usage

Currently experimenting with Bootstrap to ensure my table is responsive on a search list I am developing. However, I am facing an issue where two of my columns are taking up more space than necessary. In the image below, you can see that Date and Link colu ...

What is the best way to define a margin according to the size of the device being used

I am working on an angular/bootstrap web app and need to set a left margin of 40px on md, xl, lg devices and 0px on sm device. I attempted to create a spacer in styles.scss like this: $spacer: 1rem; .ml-6{ margin-left:($spacer*2.5); } Then in my HTML, ...

Navigate through collections of objects containing sub-collections of more objects

The backend is sending an object that contains an array of objects, which in turn contain more arrays of objects, creating a tree structure. I need a way to navigate between these objects by following the array and then back again. What would be the most ...

Guide on incorporating Vue components: implementing component 2 within the template of component 1

I'm a Vue beginner and struggling with how to use one component within the template of another or how to combine them in HTML. I've tried looking through the documentation and Stack Overflow but can't seem to figure it out. Currently, I am ...

What's the best way to add vertical space to my DIV containing buttons?

Here is an example of HTML with CSS classes that float elements left and right: <div class="block-footer"> <button class="medium float-left">A</button> <button class="medium float-left">A</button> <button class="m ...

What is the best way to place a search icon beside my label?

Hello there! I am currently working on designing in Angular 4 using bootstrap 4. I attempted to include a search icon at the end of my label. The code is as follows: <div class="row "> <div class="form-group col-lg-2"></div> <div ...

Disappearing act: conceal element when overflow is applied to x

While using overflow-y visible on the child div, a 10px section is getting hidden when hovered over. I want that 10px portion of the child to be visible. If I remove both overflow properties, it works fine. What could be causing this issue and how can it ...

Is there a way to divide a string into an array based on my loop iteration in JavaScript?

My goal is to break a string into an array during each iteration of my for-loop. For example, if the string is "1234", I want it split as ['12', '34']." I am looking to explore different ways of splitting this string such as ['1&a ...

Bulma - The Inline Imperative of Button Class

I recently started using Bulma and have been experimenting with creating a basic webpage using it. I've encountered an annoying issue where the "button is-large" class seems to be making elements on my page display inline. Below is a simple demonstr ...

disconnect from mongodb server after logging out

After initiating mongodb on my computer, I noticed that the log is being stored at /usr/local/var/log/mongodb/mongo.log. Each time I execute a query/insert/delete/update, it also gets recorded in this file. I have attempted to suppress these messa ...

Arranging an array in alphabetical order, with some special cases taken into consideration

Below is a breakdown of the array structure: [{ name: "Mobile Uploads" }, { name: "Profile Pictures" }, { name: "Reports" }, { name: "Instagram Photos" }, { name: "Facebook" }, { name: "My Account" }, { name: "Twi ...

Utilizing a regular expression to target the characters [/ , .] within the ng-pattern validation

I am struggling to come up with a regex pattern that restricts input strings from containing forward slashes, commas, or dots. <form name="myForm"> <div class="col-sm-4"> <input class="form-control" type="text" dat ...

Tips for effectively handling 404 errors when loading directive templates in AngularJS

When working with an AngularJS directive, the templateUrl parameter is dynamically specified. 'templates/' + content_id + '.html' I am looking for a way to handle situations where the value of content_id may not be valid or result in ...

Is there a way to turn off the ripple effect on Material UI Input components?

Is there a way to turn off the ripple effect or highlight color on the TextField component in React's Material UI? https://i.sstatic.net/qB2cm.png I've attempted to modify the theme: theme.props.MuiTab.disableRipple = true theme.props.MuiButto ...

Managing loading and changing events using Angular, jQuery, and Web API

I am populating a dropdown select using ng-repeat. <select onchange="ChangeMonth()" id="month"> <option ng-repeat="(key,val) in Months" ng-selected="val==ActiveMonth" value="{{key}}"> {{val}} ...

What is the best way to automatically focus on a select input field after making an

I'm currently facing an issue with the implementation of Material UI's Autocomplete component. The problem arises when I have a debounced API call triggered by user input, which temporarily disables the text input field until the call is complete ...

Gather numerical values and transform them into dates using AngularJS

My Angularjs project involves 3 scopes for year, month, and day which are retrieved from 3 input boxes. I need to combine them into a date, but the current code inserts the date with an additional 22:00:00 like 2019-06-01 22:00:00.000. How can I insert the ...

Iterate over a dictionary, display an alert for each item, and halt the loop when halfway through the

I am working with a Dict that has the following data: var seatsDict = {}; seatsDict[5] = 5; seatsDict[5] = 10; seatsDict[5] = 1; seatsDict[1] = 20; In my HTML, I have a select element structured like this: <select id="registerParticipants"> & ...

A critical issue occurred: array length is invalid. The attempt to include EJS in the template failed due to

Currently, I am attempting to loop through my JSON data using EJS from Node/Express. However, I need to insert a different pin into the flexbox when it reaches the 6th iteration. Whenever I try to implement this logic, I encounter a severe error that disr ...