Display a span element using jQuery datatable to indicate that the update operation was

I have implemented inline editing using jQuery Datatables. Currently, I am trying to display a green checkmark when a record gets updated.

Below is the ajax call that populates the table:

$.ajax({
  url: 'api/massEditorSummary.php',
  type: 'POST',
  data: data,
  dataType: 'html',
  success: function(data, textStatus, jqXHR)
  {
    var jsonObject = $.parseJSON(data); 
    var table = $('#example1').DataTable({  
      "data": jsonObject,
      "columns": [
        { "data": "partner_name" }, 
        { "data": "service" },
        {
          "data": "forecast",
          "fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
          {
                $(nTd).html("<input type='text' class='form-control editForecast' 
                id='editForecast' data-uid='"+oData.UID+"' data-editforecast='"+oData.forecast+"'
                value='"+oData.forecast+"' style='width:75px; height:30px;' /> 
               <span id='testID' style='display: none;'><i class='fa fa-check' id='updatedIcon' aria-hidden='true'
               style='color:green;'> </i></span>");
          }
        }
      ],
      "stateSave": true,
      "autoWidth": false    
    });
  },
  error: function(jqHHR, textStatus, errorThrown)
  {
    // handle errors here
  }
});

In the "forecast" data column, there is a hidden span element with an ID of testID containing a font-awesome check icon.

Now, I want to show this checkmark upon a successful update triggered by the BLUR event:

$('#example1').on('blur', 'tr > td > .editForecast', function(e) 
  e.preventDefault();
  var uid = $(this).attr('data-uid');
  var forecastcurval = $(this).attr('data-editforecast');
  var forecastnewval = $(this).val();
  var forecastData = '';

  $.post('api/inlineEditProcess.php', {uid:uid, forecastcurval:forecastcurval, forecastnewval:forecastnewval}, function(data)
  {
    forecastData = data;
    callForecastFunction(forecastData);
  });

  function callForecastFunction(forecastData)
  {
    if(forecastData == "Success")
    {
      $(this).css('display', 'inline-block'); // show the checkmark
    }
    else
    {
      // handle failure case
    }
  }
});

If the data returned from the processing script is 'success', the checkmark will be displayed in the callForecastFunction function.

Answer №1

It is important to note that having duplicate id attributes is not acceptable. Both the input and span id's should be corrected for proper functionality. To create a unique span id, you can use the UID as a base, like so:

"<span id='" + rowData.UID + "' style='display: none;'><i class='fa fa-check' id='updatedIcon' aria-hidden='true' style='color:green;'> </i></span>");

To further distinguish this solution, consider adding additional text.

Next, update the selector in the callForecastFunction() to target the span based on the UID:

$('#' + uid).css('display', 'inline-block'); // This code displays the check mark

Additionally, it appears that there might be a missing { in the event handler function:

$('#example1').on('blur', 'tr > td > .editForecast', function(e) 

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

A step-by-step guide on how to verify a selection using JavaScript

Is it possible to validate the select option with JavaScript? For example, if a user selects "Admin," then the page works for admin login. If they select "Vendor," then it works for vendor login. <table class="login_table" width="100%" border="0" cells ...

I am looking to showcase images beside individuals' names or photos on my website in a vertical arrangement, similar to how it is done on Facebook

Looking for suggestions on how to display images uploaded by users on my webpage in a way similar to Facebook, with the user's photo displayed beside each image. Any recommendations or website links would be greatly appreciated. Thanks, Santosh Sahu ...

Is the oscillator value remaining stagnant in Safari?

Is there a way to utilize the web audio API alongside NexusUI JS for dial/knobs? When I use Chrome, the dial changes the oscillator frequency, but in Safari, it seems to be playing the default 440hz. Can anyone guide me on what could be the issue or what ...

Unlocking the power of variables in Next.js inline sass styles

Is there a way to utilize SASS variables in inline styles? export default function (): JSX.Element { return ( <MainLayout title={title} robots={false}> <nav> <a href="href">Title</a> ...

The document could not be read by Jackson due to an unrecognized token 'contactForm', which was expecting either 'true', 'false', or 'null'

When attempting to send a POST request using JQuery to a Spring Controller, an error keeps popping up from JQuery. An issue arises with the following message: "Could not read document: Unrecognized token 'contactForm': was expecting ('true& ...

Utilize Google Chrome Developer Tools to interact with the "Follow" buttons on the webpage by clicking on them

https://i.stack.imgur.com/W32te.png Here is the script I am currently using: document.querySelectorAll('.components-button components-button-size-mini components-button-type-orange desktop components-button-inline').forEach(btn => btn.click() ...

Tips for managing the response from a POST request using jQuery

I'm currently working on sending data via POST to my ASP.Net MVC Web API controller and retrieving it in the response. Below is the script I have for the post: $('#recordUser').click(function () { $.ajax({ type: 'POST', ...

Using Node JS to pass variables to the client

Currently, I am utilizing Node JS and Express for my server-side needs. In my server-side code, I pass a variable (sources) to my EJS template. Part of this variable is used to populate a list on the webpage. However, when a user clicks on an item in the ...

ES6 allows for the retrieval of method data within an object

My goal is to improve the organization of my code by creating a config file where I can use the same method to set values. This is just a demonstration, so please keep that in mind. I'm wondering if there's a way to call a function based on wheth ...

Angularjs still facing the routing issue with the hashtag symbol '#' in the URL

I have recently made changes to my index.html file and updated $locationProvider in my app.js. After clicking on the button, I noticed that it correctly routes me to localhost:20498/register. However, when manually entering this URL, I still encounter a 4 ...

Using Jquery to update the information displayed in a div class to show more details about the clicked video

I am currently developing a video playlist similar to YouTube for my hybrid app. I am fetching and displaying the data using functions from json data provided by the web server. Below is a sample of the json data: [{"video_id":"1","video_youtube_title":" ...

Modify the background color based on the length of the input in Vue

Can you change the background color of the initial input field to green if the value of the Fullname input field is greater than 3 characters? See below for the code: <div id="app"> <input type="text" v-model="fullname" placeholder="Enter Full ...

How to position a popup window perfectly in the center without having direct access to the popup code

Currently, I am faced with the challenge of using software that does not allow direct editing of HTML on individual pages. Instead, I have the ability to add code to the header and footer to make modifications to the content within the body of each page. ...

Issues with functionality of Bootstrap 5 popover in responsive JavaScript DataTable

As I work on constructing a web page for my hobby, I am utilizing Bootstrap 5.3.3 and JS DataTables 2.0.5. Within the page, there is a table displaying data about various players. I have implemented a feature where clicking on certain cells triggers a popo ...

Create buttons to increase or decrease values using Bootstrap and JavaScript

What is the proper way to make this button function properly? I tested adding this line of javascript code, however it prompts an alert without clicking on the buttons as well. document.querySelector(".btnminus").addEventListener(onclick,ale ...

Tricks for refreshing cached web page assets in the year 2023

So far, here are some of the old Cache Buster techniques I've come across: Adding a query string in the link src: /mstylesheet.css?cache_buster=12345 Changing the filename each time: /mstylesheet-12345.css Using Apache with Cache-Control "must-revali ...

Validation scheme for the <speak> element

When using validators in an angular formarray for input fields, I encountered a challenge with the regex to check the <speak> tag. https://i.sstatic.net/ogFA3.png The content provided was considered valid. https://i.sstatic.net/ar5FJ.png An error ...

Encountered an issue with ReactJS app authentication using Firebase and FirebaseUI. Error message reads: "Uncaught Error: Firebase App named '[DEFAULT]-firebaseui-temp' already exists

I'm currently facing an issue in my code. I am working on a single-page web application in ReactJS with 3 tabs. Whenever the user navigates to one tab, the authentication form from FirebaseUI should appear. However, there seems to be a problem as it ...

Invoke the do_action function with JavaScript/jQuery

After successfully logging in through Facebook, my AJAX function sends information to the userpro_ajax_url. In order to run a do_action function within the success block, I am trying the following: <?php ob_start(); do_action('userpro_social_l ...

Issue with retrieving the ID of a dynamically created element with jQuery

Whenever I try to execute my function to display the id for a click event of a tag that has items appended dynamically, the alert does not show the id. Instead, it displays 'undefined'. Can anyone help me figure out where I am going wrong? Here ...