So I have a table that has about 10 items listed. When I click on a 'TR', in my javascript code, I have it set where it highlights that particular table row green. This is basically a generated grocery list and as you browse through the store, you basically "check off" your items that you have picked up.

However, me and my wife both use this since I put it on a live site and I was wondering, how would I go about checking off items (highlighting them green) on my end (my phone) say at home, and when she goes to the website, they are green or checked off for her when she views it?

So basically I say we have chicken and ground beef on the list (click on them to highlight them green), which will be highlighted when she looks at the same list on her phone.

My use-case for this is basically looking at my generated list, going into the fridge, clicking everything we already have.. and then when she gets off work, she just goes to the website, see's the already checked off items, and can go about shopping for the ones we need.

Is this possible with Javascript? Here is my current code:

(function ($, _, Drupal) {

  'use strict';

  // Here we use Drupal.behaviors which is Drupal's version for executing Javascript.
  // At the end we attach the themeID, in this case: CPU.
  Drupal.behaviors.highlight = {
    // We then use a attach function that triggers only once to apply our code.
    attach: _.once(function(context, settings) {

        // $(this).css('background', 'rgba(0,255,0,0.63');
        // console.log(this);


})(jQuery, _, Drupal);

Here is a screenshot of what it looks like:

enter image description here

  • 2
    You could set up the list as a form with hidden checkboxes, and use JavaScript to click the checkbox behind the scene. Then an #ajax call from that checkbox could be sent to the server, where you could save the checked state of the item. You would probably want to set up ajax polling on your wife's side so that updates you make while she has the app open are reflected.
    – Jaypan
    Commented Jun 19, 2021 at 15:43
  • 2
    Without getting too deep into it, essentially you'd have to do an AJAX call to a Drupal route that saves the ID as highlighted.
    – Kevin
    Commented Jun 19, 2021 at 15:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.