Create a log table specifically for tracking changes made to the drop-down menu

I need to create a Change log table that will track any changes made in the drop-down menu. For instance, I am working on a worksheet with a select menu called Results which includes options like Positive, Negative, Unknown. I want the system to log any changes from Positive to Negative or any other option with a timestamp.

Currently, I have a version of the code that works with input fields but it doesn't capture changes in the select field (drop-down menu).

Here is the code I am using for input fields, which is functioning properly:

$(document).on('focusin', 'input', function()
  {
    console.log("Saving value " + $(this).val());
    $(this).data('val', $(this).val());
   }
   ).on('change','input', function(){
    var prev = $(this).data('val');
    var current = $(this).val();
    var date1 = Date();
     if (prev !== current) {
         $(this).css("color", $currentDayColor);
         $specimenInfo = "";

    if((prev != current) && (prev!= null) && (prev != " ")){
    document.getElementById("demo").innerHTML = document.getElementById("demo").innerHTML + $specimenInfo + 'The Prev Value is :' + prev +' Which was changed on :'+ date1+'<br>';
    document.getElementById("demo2").innerHTML = document.getElementById("demo2").innerHTML + $specimenInfo + ' The Current Value is :' + current +' Which was changed on :'+ date1 + '<br>';
    console.log("Prev value " + prev);
    console.log("New value " + current);
    }
     };
});

Answer №1

If your form fields are functioning properly, you can easily switch from using 'input' to 'select' in your jQuery selector. Here is an example:

$(document).on('focusin', 'select', function()
  {
    console.log("Saving value " + $(this).val());
    $(this).data('val', $(this).val());
   }
   ).on('change','select', function(){
    var prev = $(this).data('val');
    var current = $(this).val();
    var date1 = Date();
     if (prev !== current) {
         $(this).css("color", $currentDayColor);
         $specimenInfo = "";

    if((prev != current) && (prev!= null) && (prev != " ")){
    document.getElementById("demo").innerHTML = document.getElementById("demo").innerHTML + $specimenInfo + 'The Prev Value is :' + prev +' Which was changed on :'+ date1+'<br>';
    document.getElementById("demo2").innerHTML = document.getElementById("demo2").innerHTML + $specimenInfo + ' The Current Value is :' + current +' Which was changed on :'+ date1 + '<br>';
    console.log("Prev value " + prev);
    console.log("New value " + current);
    }
     };
});

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

Navigating with buttons in React JS

In my material-ui, I have a button set up like this: <Button style={green} raised="true" label="Continue to create group"}> CREATE NEW GROUP </Button> I am looking to make it so that when the button is clicked, it will take me ...

Tips for seamlessly incorporating WalletConnect into your decentralized app with the help of web3-react

I have been working on integrating WalletConnect into my project by referring to the documentation provided by web3-react. The configuration settings I am using for the connector are as follows: import { WalletConnectConnector } from '@web3-react/wal ...

Unlock the ability to retrieve the current Ember route directly within a component

I have a unique custom Ember component embedded within a controller. Currently, I am attempting to dynamically retrieve the name of the current route. In order to access the controller, I use: this.get('parentView') However, I am facing diffi ...

Picture emerges from the lineup

My dilemma involves repositioning an image within a row > col-md-6. To address this, I devised two classes - .pos1 and .pos2 .pos1 { position: relative; } .pos2 { position: absolute; right: 0px; } However, when applying these classes, the ...

"Troubleshooting issue: Unable to retrieve grid data from Google Sheets API v4 when integrated

I've implemented a function within a React component that retrieves JSON data from an API request and logs it: async function getAllSheets() { let response; try { response = await window.gapi.client.sheets.spreadsheets.values.batchGet( ...

Adjust the appearance of an element in a different parent when hovering over a specific element with a matching index

I have implemented a menu on my site in two different ways - one using text and the other using pictures. Users can click on both types of menus. Now, I am looking to create an interactive feature where hovering over a specific item in the text menu (such ...

Unfocus element in IE11

Currently, I am dealing with an issue involving the following image: The main problem arises when the jQuery UI tooltip fails to close properly after I close a modal window that was opened by clicking on the link associated with the tooltip. Interestingl ...

Continuously iterate through collection as it expands over time

As I cycle through an array, I'm performing additional actions that could potentially prolong the loop if new elements are added to the array during iteration. (I understand it's not recommended to modify the object being iterated over, but pleas ...

Using React to access a function from a different component in your application

I am working on implementing a topbar menu that requires access to a specific react component. The challenge I am facing is that within the topbar file, I do not directly render the components I need to interact with but still want to be able to call a fun ...

Switching a cookie from JavaScript to AngularJS: A step-by-step guide

Getting a cookie in AngularJS can be done in a more standardized way. Instead of the traditional JavaScript approach, you can implement it using AngularJS code as shown below: angular.module('myApp', []) .factory('CookieService', func ...

I'm only getting a single row in my query output. What could be causing this?

I have been working on disabling dates in a jQuery UI date picker using data from my database. The code I have written is almost functioning correctly, but it seems to only be reading one row of data from the database. Despite having two bookings stored in ...

The message "jest command not recognized" appears

My test file looks like this: (I am using create-react-app) import React from 'react'; import ReactDOM from 'react-dom'; import App from './components/Calculator'; import { getAction, getResult } from './actions/' ...

Code is not running in ReactJS

My challenge is to use canvas and script to draw a rectangle with one diagonal line. However, when I try to do so, only the rectangle appears on my browser. It seems like the script is not being executed. Here's the code: import React, { Component } ...

Tips for utilizing the npm jQuery module effectively

What is the best way to import jquery into multiple modules in node? Should I make it a global variable, or should I use require('jquery') in each module that needs it? I encountered an error while attempting to utilize the package. TypeError: ...

I am having trouble creating a modal box for my gallery images

I'm currently working on a PHP dynamic site and I've encountered an issue with my gallery code. For some reason, the modal box is not showing up when I click on the gallery images. Can anyone please assist me in resolving this problem? var mod ...

Tips for resolving dependency conflicts in a JavaScript project starter template

Currently, I'm utilizing the Airframe React template and the procedure seems quite simple: Extract the files and execute npm install in the project directory. However, an issue arises when running npm install as follows: npm WARN config global `--glob ...

Tips for enhancing the fluidity of animations after removing an item from a list

I'm working on a project where I have a list of elements that are removed with an animation when clicked. However, I noticed that when one element is removed, the rest of the elements just jump up instead of smoothly transitioning. Is there a way to m ...

What technique is used in this CSS code to give each line of text a unique horizontal color gradient?

I stumbled upon a fascinating jsfiddle that can create color gradients on specific lines of text. Each line has a unique two-color gradient applied in a consistent pattern: Black to Red, Red to Black, Black to Blue, and Blue to Black. Despite its intrigui ...

Switch the website title as soon as the user looks away from the tab

How can I capture the user's attention and bring them back to my website when they are on a different tab? I really like the effect used on sephora.pl where an alert pops up with the message 'What are you waiting for?' when you switch tabs. ...

Unable to invoke the 'apply' method on an undefined object when configuring directions for the jQuery Google Maps plugin

I've gone through the steps in a tutorial to create a jquery mobile google map canvas here, and have attempted to set it up. However, I keep encountering this error in my JavaScript console: Uncaught TypeError: Cannot call method 'apply' ...