Javascript var variable not working as global

I have a variable declared as counts before the add_to_download_entries() function and I am using it later in the $(document).ready( function () { function but it always print the value 1 of count however when I tested the value of count changes depending on how many checboxes are selected in the add_to_download_entries but it’s not reflected the same value outside that function in the $(document).ready( function (). Am I using the variables wrong?

Close
Pay Now $

var selected_lostwill_array = [];

var counts = 1;
var checkboxes;

function add_to_download_entries(data) {
  checkboxes = document.querySelectorAll('input[name="checkWills"]:checked');
  counts = checkboxes.length;
  if ($.inArray(data, selected_lostwill_array) >= 0) {
    selected_lostwill_array = $.grep(selected_lostwill_array, function(value) {
      return value != data;
    });
  } else {
    selected_lostwill_array.push(data);
  }
}
// DataTables Functions 
$(document).ready(function() {
  $('#org_lost_table').DataTable();
  $('#all_lost_table').DataTable();
  if (counts > 0) {
    let finalPrice = Number(counts) * Number(22);
    $("#payment-sub-btn").append(counts);
  } else $("#payment-sub-btn").append(0);
});
<td>
  <input type="checkbox" name="checkWills" onclick='add_to_download_entries("{{$will->id}}")' />&nbsp;
</td>

Keep checking if a function returns true in local storage

I’m trying to check if a function returns true in an if/else statement, however I want to keep checking if the function returns true and when it does to execute the code…

How would I go about this? I have tried setInterval and setTimeout and it won’t repeat, unless I’m missing something…

I have also tried a while loop but this is inefficient and crashes the browser…

However if I use an setInterval() how would I clear it once x returns true?

Here is a snippet of my code for an example.

function x() {
    if (localStorage.getItem("a") === null) {
        return false;
    } else {
        return true;
    }
}

if (!x()) {
    console.log("Returned True!");
    update();
} else {
    console.log("False");
}

How to show color on box after clicking color name

I want to show the color on color box after clicking the color name.

Here is my javascript code so far and also HTML and css code.
i tried take value but its not working , i don’t know how to take this value. you must create one event handler and assign it too all 3
buttons. Your code should be written as the last examples that we have done in
class. Assign the event handler through the CLASS, but use the ID to distinguish
which button got clicked on.

$(document).ready(function() {
  $(".colorbutton").on("click", function() {
    var colorid = $(this).attr("id");

    $("#output").stop(true, true).hide().html(color).stop(true, true).show("fade", 1500);
  }); // end event handler
}); // ends document.ready
body {
  background-image: url("https://newton.ncc.edu/gansonj/ite154/img/crayons.jpg");
  font-family: arial;
  text-align: right;
  color: #008B8B;
}

#pagewrap {
  border: 8px #800000 solid;
  padding: 10px;
  width: 600px;
  border-radius: 25px;
  text-align: center;
  background: white;
  margin: 40px auto 0px auto;
}

#title {
  font-size: 2.2em;
  border-bottom: 7px #008B8B double;
  padding: 10px 0px 10px 0px;
  color: #008B8B;
  text-align: center;
}

#formtext {
  text-align: center;
  font-size: 1.29em;
  margin-top: 20px;
}

#usergrade {
  text-align: center;
  margin: 5px 20px 10px 20px;
}

.colorbutton {
  color: white;
  cursor: pointer;
  padding: 5px 0px 5px 0px;
  border: 3px solid #CCCC99;
  border-radius: 25px;
  width: 150px;
}

.colorbutton:hover {
  background: #CCCCCC;
  color: yellow;
  border: 3px solid #003366;
}

#output {
  font-size: 5em;
  padding-top: 100px;
  width: 200px;
  height: 100px;
  margin: 30px auto 30px auto;
  border: 5px black double;
  font-size: 1em;
  font-family: arial;
}
<html>

<head>
  <title></title>

  <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>

</head>

<body>

  <div id="pagewrap">

    <div id="title">Crayon Color Factory</div>

    <div id="formwrap" style="margin-top: 30px;">

      <input type="button" class="colorbutton" id="red" style="background-color:red;" value="RED Color">
      <input type="button" class="colorbutton" id="blue" style="background-color:blue;" value="BLUE Color">
      <input type="button" class="colorbutton" id="green" style="background-color:green;" value="GREEN Color">

      <div id="output">Change Me!!!!!</div>

    </div>
    <!-- ends div#formwrap -->

  </div>
  <!-- ends div#pagewrap -->

</body>

</html>

smaple picture here: enter image description here

Checkbox disabel

I have created several checkboxes (4) in html. Now I want to program with javascript that there is basically only 1 option, so only one checkbox can be ticked with it. Probably not that difficult. Problem: I only worked with Java during my training and now I have to do it for a colleague who is currently ill. Since I currently have Corona and during the Easter holidays in Germany I feel like I’m the only one who works, I can’t ask a colleague how it is to do.

I tried what would be logical for me and what I knew with my little javascript knowledge. So:

if (getElementById("Haken1")==true) { getElementById("Haken2")==false; }
I thought that might work, but didn’t.

Why my github pages project wont fetch API?

Okay, so im currently building a webpage, that fetches and displays weather data from API. Using live server in vscode, all works and is displayed correctly. However, when i deployed to github pages, it doesnt fetch data from API, hence it leaves my js built dynamic table unfilled, and my chart.js wont display at all, because there is nothing to display. Im a novice in programming, so i cant figure out why this doesnt work. I have double checked all filepaths, enabled mixed content by including <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> (due to my API being http), and triple checked my js file. Devtools network tool shows that it doesnt try to fetch anything. Js is properly linked and accepts logs.

Currently project is displayed at https://krisbis.github.io/WeatherApiUI/ . Im trying to solve “temperature.html” & “windspeed.html”, which both are built similarly. Heres snippet of my js fetch:

`async function fetchTempTwenty(table) {
  try {
    const response = await fetch(tempTwentyAPI);
    const apiData = await response.json();

    // Extract the temperature values from the API data
    const temperatures = apiData.slice(-20).map((data) => data.temperature);
    const times = apiData.slice(-20).map((data) => data.date_time);
    console.log(temperatures);

    // Create the Chart.js chart
    const canvas = document.getElementById("myChart");
    const chart = new Chart(canvas, {
      type: "line",
      data: {
        labels: [...Array(20).keys()].map((i) => `Reading ${i + 1}`),
        datasets: [
          {
            label: "Temperature",
            data: temperatures,
            backgroundColor: "cyan",
            borderColor: "cyan",
            borderWidth: 1,
          },
        ],
      },
      options: {
        scales: {
          yAxes: [
            {
              ticks: {
                beginAtZero: true,
              },
            },
          ],
        },
      },
    });

    // Create the table of information
    const tableHead = table.querySelector("thead");
    const tableBody = table.querySelector("tbody");
    tableHead.innerHTML =
      '<tr><th scope="col">#</th><th scope="col">Time</th><th scope="col">Temperature</th>   </tr>';
    tableBody.innerHTML = "";
    for (let i = 1; i < times.length; i++) {
      const t = times[i];
      const c = temperatures[i];
      const cellElement = document.createElement("tr");
      cellElement.innerHTML =
        '<td scope="row">' +
        i +
        "</td><td>" +
        convertTime(t) +
        "</td><td>" +
        c +
        " °C" +
        "</td>";
      tableBody.appendChild(cellElement);
    }
  } catch (error) {
    console.log(error);
  }
}
// Conditional call for the function - could've done it inside
// the code block, but this seemed to bring more clarity to code
if (window.location.pathname === "/temperature.html") {
  window.addEventListener(
    "load",
    fetchTempTwenty(document.querySelector("table"))
  );
}`

Heres html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

    <title>Document</title>

    <link
      href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
      crossorigin="anonymous"
    />
    <link rel="stylesheet" href="./css/stylesheet.css" type="text/css" />
  </head>
  <body>
    <div class="hero">
      <nav
        class="navbar navbar-expand-sm navbar bg-transparent"
        id="custom_navbar_styles"
      >
        <a href="./index.html" class="navbar-brand mx-4 p-0"
          ><div class="text-black-50 h2">Weather</div></a
        >
        <button
          class="navbar-toggler navbar-light"
          type="button"
          data-bs-toggle="collapse"
          data-bs-target="#main-navigation"
        >
          <span class="navbar-toggler-icon"></span>
        </button>
        <div id="main-navigation" class="collapse navbar-collapse">
          <ul class="navbar-nav ms-auto text-center mx-2">
            <li class="nav-item">
              <a class="nav-link" href="./last50readings.html"
                >Last 50 readings</a
              >
            </li>
            <li class="nav-item">
              <a class="nav-link" href="./windspeed.html">Windspeed</a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="./temperature.html">Temperature</a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="#">-</a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="#">-</a>
            </li>
          </ul>
        </div>
      </nav>
    </div>
    <br />
    <br />
    <div class="chart_container d-flex">
      <canvas id="myChart"></canvas>
    </div>
    <br>
    <br>
    <div class="container d-flex">
      <table class="table table-hover table-striped table-borderless">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">Time</th>
            <th scope="col">Temperature</th>
          </tr>
        </thead>
        <tbody>
          <!-- Dynamic table from JS -->
        </tbody>
      </table>
    </div>

    <script
      src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
      crossorigin="anonymous"
    ></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="./js/script.js"></script>
    <script src="https://krisbis.github.io/WeatherApiUI/js/script.js"></script>
  </body>
</html>

How can i get or retrieve the comments on a intagram post

Im creating a app for raffles that chooses a winner from all the coments in a instagram post, how can i use the instagram api to retrieve the comments ?

The meta site is pretty confusing, i already have my token that i created in my app but when i make a get request to https://graph.instagram.com/POST_ID/comments?access_token=ACCESS_TOKEN, replacing the fields i get the im not authorized to get this info, can someone explain what permissions i need ? With this permision will i be able to get all comments from any public post ?

JavaScript Axios GET response is not being stored in global variable

I am trying to store the API response in the async/await functions into the response global variable which will be later accessed by App() but I am being prompted with the error shown below the code.

async function getAllTutors() {
    try{
        const response = await axios.get('API...');
        console.log("getAllTutors(): " + JSON.stringify(response.data.body));
        return response;
    }catch(error) {
        return [];
    }
    
}

var response = null;
(async () => {
    console.log("Retrieving Tutors");
    response = await getAllTutors();
    console.log("response (caller) = " +  JSON.stringify(response.data.body))
  })();

  
function App() {
...
    console.log("HERE: " + JSON.stringify(response.data.body));
    const [ data, setTutors ] = useState(employees);
...

error screenshot

I tried logging the values while in both functions and it does seem to output the desired JSON object but, App() still shows response variable to be undefined. I even tried to change App() to be async/await but I am being lead into other errors.

Javascript: move elements in an array but based on another array data

Here’s what i’m trying to do. I have an Array arr with strickly 4 elements. can’t have more and can’t have less. I have another Array called shiftAmounts.
So here’s what I have and the result i’m looking for…

arr[A, B, C, D]
shiftAmounts[0, 1, 1, 3]
result: arr[A,"Empty", B, C]

So starting from the right (the fouth elements) it<s important, I have to move the D to the right by 3 space. Since I can’t have more than 4 elements, then it’s deleted
Next the C move one space to the right
Next the B move one space to the right
Next the A don’t move cause it has 0.
Elements never cross each others.
The change has to be in place.
tks for your help
Seby

When will Javascript garbage collector delete variables that are covered by closure relations?

I’m receiving chunks of data asynchronrously via SSE and it is slowly but surely populating a dictionary {UPD.x, UPD.y}, whose contents I want to display with ploty.js. I want to see the graph steadily update as more chunks arrive.

I do the plotly calls similar to this

eventSource.onmessage = function(event) { 
   const data = json.parse(event.data);
   const UPD = data.upd;
   Plotly.update (PLOTTER, UPD, [0]);
}

where PLOTTER is global in the calling program. My thought is that while UPD is local to that function, the update command copies the reference as PLOTTER.data = UPD and so UPD should survive any garbage collection as long as PLOTTER stays alive at least until the next batch of data arrives, when the old UPD would get garbage collected.

A) Do I have that correct?

B) Taking this one step further, I really just want to be sure to display the last graph, I don’t really care if I “miss” some plots of partial data. If new data has arrived since the last promise to Plotly.update() was issued then I’d really just want to blow off that earlier call. I think a solution to that could be to make UPD itself global to the function. What are the potential downfalls to that? Worst case that I can see is that it could result in a few extra calls to Plotly.update if the data arrives ahead of the plot. But maybe there could be an obscure race condition if UPD updates in the middle of a plot…

how can i change the url of an existing page on my website?

I want the same page to open but with another url for example;

<li><a href="@(Utils.getKullaniciKayit()==null?Url.Action("Login","Home",new {Area="Kayit"}):Url.Action("Ekle","Randevu",new {Area="Kayit"}))" id="randevualUrl"  onclick="changeRandevuUrl();">@("RANDEVU AL".ToGecerliDileCevir())</a></li>

this href is as follows: /Kayit/tr/Home/Login
I want it to open with the following url:
/RandevuAl an appointment shaped

How do I use firebase google sign in, server side on replit

I am coding a firebase sign in and hosting it on replit but each time I try to sign in wtih google I get this errror {“code”:”auth/operation-not-supported-in-this-environment”,”customData”:{},”name”:”FirebaseError”}. I have sign in with google active in my firebase authentication dashboard, also signing in with email and password works. Please help.

If you want to check out my code the github link is here https://github.com/ObviousTeam/firebase-auth

Also my github page is here https://replit.com/@ozabramo/take-6#accountmanagement/login.js

Update image using flask and Ajax

Running a webpage and when I click a button, I want an existing image to be replaced without reloading the page, after a servers function is finished creating the new image server side. I am getting a 400 error though, so something is wrong before I can even print the data in routes.py to see what it’s passing, meaning something is wrong with my ajax call to my flask routes.py function.

The image:

        <div class="col-6">
            <div class="card">
                <img src="{{ user_image }}" alt="User Image" id="myImage"> 
            </div> 
        </div>

At the end of my html file I have this script as an attempt to replace the existing image:

</body>
<script>
    $(document).ready(function() {
      $('#makeNewImage').click(function(){
        $.ajax({
          type: 'POST',
          url: "{{ url_for('getData') }}",
          headers: {"Content-Type": "application/json"},
          success: function(resp){
            $('myImage').attr('src', "static/img/" + resp);
          }
        });
      });
    });
  </script>
  </html>

In my flask routes.py page:

 @app.route('/getData', methods=['POST'])
 def getData():
     // generate image, save image in /static/img/filename
     return filename

Passing data and everything works when I use my original xhr function, but it isn’t auto updating as it’s pure JS. I receive the 200 message with this function.

function getResults() {
  let xhr = new XMLHttpRequest();
  let url = "/getData";
  let error = false;
  if (!Array.isArray(myArray) || !myArray.length) {
    alert("No items selected.")
    error = true;
  } else {
  xhr.open("POST", url, true);
  xhr.setRequestHeader("Content-Type", "application/json");
  xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        console.log("I see this as an absolute win")
      }
    };
    xhr.onerror = function () {
      console.log("** An error occurred during the transaction");
    };
    param1 = document.getElementById('param1').value
    param2 = document.getElementById('param2').value
    param3 = document.getElementById('param3').value
    let data = JSON.stringify({"myArray": myArray, "param1 ": param1 , "param2 ": param2, "param3": param3});
    xhr.send(data);
    }
}

Anyone know the reason for the 400 error on my new Ajax code attempt?

Why would this JavaScript work when hosted but not when offline?

When using this code to sort pixels, the code works fine with the default image when hosted online. However, when testing the script offline, the default image loads but does not process correctly through the sorter. What is causing the behavior to work in an online hosted environment but not in a localized, offline environment?

See online code here: http://birdhat.org/misc/sort-pixels/

var READY_STATUS = '&nbsp;'
var FIRSTLOAD_STATUS = '&nbsp;';
var SORTING_STATUS = 'Sorting (be patient)';
var FINISHING_STATUS = 'Finishing up...';
var FILENAME = null;
var SORTING_FILENAME = null;
var STATE = 'ready';

//================================================================================
// UTILS

var rgb2hsv = function(r, g, b) {
  // given r,g,b in the range 0-255,
  // return [h,s,v] in the range 0-1
  var rr, gg, bb,
    r = r / 255,
    g = g / 255,
    b = b / 255,
    h, s,
    v = Math.max(r, g, b),
    diff = v - Math.min(r, g, b),
    diffc = function(c) {
      return (v - c) / 6 / diff + 1 / 2;
    };
  if (diff == 0) {
    h = s = 0;
  } else {
    s = diff / v;
    rr = diffc(r);
    gg = diffc(g);
    bb = diffc(b);

    if (r === v) {
      h = bb - gg;
    } else if (g === v) {
      h = (1 / 3) + rr - bb;
    } else if (b === v) {
      h = (2 / 3) + gg - rr;
    }

    if (h < 0) {
      h += 1;
    } else if (h > 1) {
      h -= 1;
    }
  }
  return [h, s, v];
};

//================================================================================
// INTERFACE

var setStatus = function(msg) {
  document.getElementById('status').innerHTML = msg;
};

//================================================================================
// SORTING

var sortOneStep = function(sort_list, my_canvas, context, ii) {
  // do one step of sorting and queue up the next one

  var first_is_horizontal = 1;

  // on first step, remember the filename
  if (ii == 0) {
    SORTING_FILENAME = FILENAME;
  }

  // if the filename has changed, stop
  if (ii > 0 && FILENAME != SORTING_FILENAME) {
    finish(my_canvas, false); // need to avoid copy here or something
    return;
  }

  // stop when we've finished all the sorts
  if (ii >= sort_list.length) {
    finish(my_canvas, true);
    return;
  }

  sortImage(my_canvas, context, ii, (ii + first_is_horizontal) % 2, sort_list[ii]);
  var bar_chars = [];
  for (var char_ii = 0; char_ii < sort_list.length; char_ii++) {
    if (char_ii <= ii) {
      bar_chars.push('=');
    } else {
      bar_chars.push('&nbsp;');
    }
  }
  setStatus(SORTING_STATUS + ' <code>[' + bar_chars.join('') + ']</code>');
  var timeout_length = 100;
  //if (ii === 1) { timeout_length = 2500; }
  setTimeout(function() {
    sortOneStep(sort_list, my_canvas, context, ii + 1);
  }, timeout_length);
};

var finish = function(my_canvas, done) {
  setStatus(FINISHING_STATUS);
  var my_image = document.getElementById('my-image');
  if (done) {
    my_image.src = my_canvas.toDataURL('image/png');
  }
  my_image.className = '';
  my_canvas.className = 'invisible';
  setStatus(READY_STATUS);
  console.log('DONE');
  STATE = 'ready';
  document.getElementById('sort-button-quick').className = 'ready-button';
  document.getElementById('sort-button-thorough').className = 'ready-button';
}

var sortImage = function(my_canvas, context, ii, is_horizontal, kind) {
  // sort the entire image

  var dir_name;
  if (is_horizontal) {
    dir_name = 'horizontal';
    for (var y = 0; y < my_canvas.height; y += 1) {
      sortRegion(context, 0, y, my_canvas.width, 1, kind);
    }
  } else {
    dir_name = 'vertical';
    for (var x = 0; x < my_canvas.width; x += 1) {
      sortRegion(context, x, 0, 1, my_canvas.height, kind);
    }
  }
  console.log('' + ii + ' -- sorted ' + dir_name + ' by ' + kind);
};

var sortRegion = function(context, x, y, width, height, kind) {
  // sort a rectangular region of the image, usually a single row or column of pixels
  // kind should be one of: random, semirandom, v, h, h2, s, magic

  // fetch image data
  var imgData = context.getImageData(x, y, width, height);
  var data = imgData.data;

  // convert to sortable pixel array
  var pixels = [];
  for (var ii = 0; ii < imgData.data.length; ii += 4) {
    var pixel = [data[ii], data[ii + 1], data[ii + 2]];

    switch (kind) {
      case 'v':
        var sortValue = -(pixel[0] + pixel[1] + pixel[2]);
        var sortValue = -(pixel[0] * 0.30 + pixel[1] * 0.59 + pixel[2] * 0.11);
        break;
      case 'semirandom':
        var sortValue = ii / 4 + Math.random() * 25;
        break;
      case 'random':
        var sortValue = Math.random();
        break;
      default:
        hsv = rgb2hsv(pixel[0], pixel[1], pixel[2]);
        var h = hsv[0];
        var s = hsv[1];
        var v = (pixel[0] + pixel[1] + pixel[2]) / (255 * 3);
        if (kind === 'magic') {
          var sortValue = 1 - ((h + 0.2) % 1);
          if (s < 0.07) {
            if (v < 0.5) {
              sortValue = v - 300;
            } else {
              sortValue = v + 300;
            }
          } else {
            if (v < 0.2) {
              sortValue = v - 300;
            };
            if (v > 0.9) {
              sortValue = v + 300;
            };
          }
        } else if (kind === 'h') {
          var sortValue = h;
        } else if (kind === 'h2') {
          var sortValue = (h + 0.15) % 1;
          if (s < 0.07) {
            sortValue -= 900;
          }
        } else if (kind === 's') {
          var sortValue = s;
        }
    }

    pixels.push([sortValue, pixel]);
  }

  // sort
  pixels.sort(function(a, b) {
    return a[0] - b[0];
  });

  // write back to data array and then back to canvas
  for (var jj = 0; jj < pixels.length; jj++) {
    var pixel = pixels[jj][1];
    data[jj * 4 + 0] = pixel[0];
    data[jj * 4 + 1] = pixel[1];
    data[jj * 4 + 2] = pixel[2];
  }
  context.putImageData(imgData, x, y);

};

//================================================================================
// MAIN
var wo = window.onload;
window.onload = function() {
  wo && wo.call(null);

  setStatus(FIRSTLOAD_STATUS);


  var handleDragOver = function(evt) {
    evt.stopPropagation();
    evt.preventDefault();
    evt.dataTransfer.dropEffect = 'copy';
    dropZone.className = 'big-border';
  };

  var handleDragLeave = function(evt) {
    evt.stopPropagation();
    evt.preventDefault();
    dropZone.className = '';
  };

  var handleFileDrop = function(evt) {
    // when the user drops a file,
    // load it into an img tag
    // and then copy the data into the canvas
    console.log('[handleFileDrop]');
    evt.stopPropagation();
    evt.preventDefault();

    dropZone.className = '';

    var files = evt.dataTransfer.files;

    // only allow one file to be dropped
    if (files.length !== 1) {
      return;
    }

    for (var ii = 0; ii < files.length; ii++) {
      var file = files[ii];
      FILENAME = file.name;
      console.log(FILENAME);

      // only allow images
      if (!file.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();
      reader.onload = (function(theFile) {
        return function(e) {
          droppedImageTag = document.getElementById('my-image').src = e.target.result;
        };
      })(file);

      reader.readAsDataURL(file);
    }
  };

  var body = document.getElementById('body');
  var dropZone = document.getElementById('drop-zone');
  body.addEventListener('dragover', handleDragOver, false);
  body.addEventListener('dragleave', handleDragLeave, false);
  body.addEventListener('drop', handleFileDrop, false);

  var copyImgToCanvas = function(image_id, canvas_id) {
    console.log('[copyImgToCanvas] ' + image_id + ' --> ' + canvas_id);
    var my_image = document.getElementById(image_id);
    var my_canvas = document.getElementById(canvas_id);
    var context = my_canvas.getContext('2d');

    my_canvas.width = my_image.width;
    my_canvas.height = my_image.height;

    my_canvas.className = '';
    my_image.className = 'invisible';

    context.drawImage(my_image, 0, 0);
  };

  var handleButtonClick = function() {
    STATE = 'sorting';
    console.log('[click]');
    setStatus(SORTING_STATUS);
    document.getElementById('sort-button-quick').className = 'disabled-button';
    document.getElementById('sort-button-thorough').className = 'disabled-button';
  };

  var launchSorting = function(sort_list) {
    var my_canvas = document.getElementById('my-canvas');
    var context = my_canvas.getContext('2d');
    copyImgToCanvas('my-image', 'my-canvas');
    sortOneStep(sort_list, my_canvas, context, 0);
  };

  document.getElementById('sort-button-quick').onclick = function() {
    if (STATE === 'sorting') {
      return;
    }
    handleButtonClick();
    // random, semirandom, v, h, h2, s, magic
    var sort_list = ['semirandom', 'v']
    setTimeout(function() {
      launchSorting(sort_list)
    }, 1)
  };
  document.getElementById('sort-button-thorough').onclick = function() {
    if (STATE === 'sorting') {
      return;
    }
    handleButtonClick();
    // random, semirandom, v, h, h2, s, magic
    var sort_list = ['h2', 'v', 'h2', 'v', 'h2', 'v', 'h2', 'v', 'h2', 'v', 'h2', 'v', ];
    setTimeout(function() {
      launchSorting(sort_list)
    }, 1)
  };
  document.getElementById('sort-button-quick').className = 'ready-button';
  document.getElementById('sort-button-thorough').className = 'ready-button';
};
body {
  text-align: center;
  padding: 0px;
  margin: 0px;
  color: #bbb;
  font-family: 'Helvetica Neue', Helvetica, sans-serif;
  background: #333;
  font-size: 14px;
  line-height: 20px;
}

#copy {
  background: #000;
  padding: 10px;
  padding-left: 30px;
  padding-right: 30px;
  text-align: left;
}

#topbar {
  text-align: left;
}

#sort-button-quick {
  padding: 12px;
  display: inline-block;
  text-align: center;
  border-style: solid;
  border-width: 2px;
  margin-left: 30px;
}

#sort-button-thorough {
  padding: 12px;
  display: inline-block;
  text-align: center;
  border-style: solid;
  border-width: 2px;
  margin-left: 15px;
}

.ready-button {
  background: #777;
  color: white;
  border-color: white;
}

.ready-button>a {
  color: white;
  text-decoration: none;
}

.disabled-button {
  font-style: italic;
  background: #606060;
  color: #ccc;
  border-color: #bbb;
}

.disabled-button>a {
  color: #ccc;
  text-decoration: none;
}

#status {
  padding: 12px;
  display: inline-block;
  color: #ff8;
}

#drop-zone-wrapper {
  background: #000;
}

#drop-zone {
  padding-top: 50px;
  padding-bottom: 50px;
  background: #000;
  border-radius: 30px;
  border-style: dashed;
  border-color: black;
  border-width: 10px;
}

.big-border {
  border-color: #aaa !important;
}

.invisible {
  display: none;
}

.dotted {
  border-style: dotted;
  border-color: red;
  border-width: 1px;
}
<!DOCTYPE html>
<html>

<head>
</head>

<body id="body">

  <div id="copy">
    <h3> Image pixel sorter </h3>
    <p>
      Drag an image from your computer into this page, then click Sort. The pixels will be sorted vertically by brightness and horizontally by hue.
    </p>
    <p>
      To use an image from the web, drag it to your desktop first and then into this page. Use small images or it will be very slow.
    </p>
    <p>
      <a href="http://sorted-pixels.tumblr.com/" style="color:#8af;">Blog of results</a>
    </p>
  </div>

  <div id="topbar">
    <div id="sort-button-quick" class="disabled-button"><a> Two-Step Sort </a></div>
    <div id="sort-button-thorough" class="disabled-button"><a> Twelve-Step Sort </a></div>
    <div id="status">&nbsp;</div>
  </div>

  <div id="drop-zone-wrapper">
    <div id="drop-zone">
      <canvas id="my-canvas" width=100 height=100 class="invisible"></canvas>
      <img id="my-image" src="img/sunset.png">
    </div>
  </div>

</body>

</html>

I’ve tried moving the images, rerouting the sources for the loading of them, moving the image loading into the onload function… I have the sunset.png default image in an img folder with code. It displays correctly, but does not execute the pixel sorting when offline.

Column Totaling

I need it to update the column totals when the row updates so I assume I can add it into the current script but I am in over my head.

I am using the below script to total the rows:

<script>
function total_amount(){
        var table = document.getElementById('line_item');
        for(var i=1;i<table.rows.length;i++){
            qty = table.rows[i].cells[1].getElementsByTagName("input")[0].value
            unit = table.rows[i].cells[2].getElementsByTagName("input")[0].value
            table.rows[i].cells[3].getElementsByTagName("input")[0].value = qty * unit;
        }
    }
</script>

I am looking to do the same with the column that this script returns. I have attempted and failed to convert this to a column script, I tried several different totaling scripts but since I need it to update after the user updates their part I seem to keep breaking it.

My table

<table class="table table-striped" id="line_item" data-togle="table" data-sort-stable="true">
  <thead>
    <tr>
      <th>
        Product
      </th>
      <th>
        Quantity
      </th>
      <th>
        Price Unit
      </th>
      <th>
        Amount
      </th>
<th>
Date of Service
</th>
    </tr>
  </thead>
  
  <tbody>
<tr>
      <td id="col0">
[select SERVICES1]</td>
      <td id="col1">
        [number Quantity onblur="total_amount()"]
      </td>
      <td id="col2">
        <input class="form-control" type="number" placeholder="Price Unit" id="unit" onblur="total_amount()">
      </td>
      <td id="col3" class="count-me">
        [number amount]
      </td>
<td>[date DOS1]</td>    </tr>
    <tr>
      <td id="col0">
       [select SERVICES2]
      </td>
      <td id="col1">
        [number Quantity2 onblur="total_amount()"]
      </td>
      <td id="col2">
        <input class="form-control" type="number" placeholder="Price Unit" id="unit2" onblur="total_amount()">
      </td>
      <td id="col3" class="count-me">
        [number amount2 readonly]
      </td>
<td>[date DOS2]</td>    </tr>
    <tr>
      <td id="col0">
[select SERVICES3]      </td>
      <td id="col1">
        [number Quantity3 onblur="total_amount()"]
      </td>
      <td id="col2">
        <input class="form-control" type="number" placeholder="Price Unit" id="unit3" onblur="total_amount()">
      </td>
      <td id="col3" class="count-me">
        [number amount3 readonly]
      </td>
<td>[date DOS3]</td>    </tr>
    <tr>
      <td id="col0">
  [select SERVICES4]
      </td>
      <td id="col1">
        [number Quantity4 onblur="total_amount()"]
      </td>
      <td id="col2">
        <input class="form-control" type="number" placeholder="Price Unit" id="unit4" onblur="total_amount()">
      </td>

Add “a” tag to Highcharts Org Chart

I am going to make some changes in Highcharts Org Chart. I want to add an “a” tag to only one of the nodes of Highcharts Organization Chart ][enter link description here][1]
For example I want to change’board’ node to an ‘a’ tag so the user can be able to click on it. can you please help me How can I do that?
Thank you so much

Highcharts.chart('container', {
    chart: {
        height: 600,
        inverted: true
    },

    title: {
        text: 'Highcharts Org Chart'
    },

    accessibility: {
        point: {
            descriptionFormatter: function (point) {
                var nodeName = point.toNode.name,
                    nodeId = point.toNode.id,
                    nodeDesc = nodeName === nodeId ? nodeName : nodeName + ', ' + nodeId,
                    parentDesc = point.fromNode.id;
                return point.index + '. ' + nodeDesc + ', reports to ' + parentDesc + '.';
            }
        }
    },

    series: [{
        type: 'organization',
        name: 'Highsoft',
        keys: ['from', 'to'],
        data: [
            ['Shareholders', 'Board'],
            ['Board', 'CEO'],
            ['CEO', 'CTO'],
            ['CEO', 'CPO'],
            ['CEO', 'CSO'],
            ['CEO', 'HR'],
            ['CTO', 'Product'],
            ['CTO', 'Web'],
            ['CSO', 'Sales'],
            ['HR', 'Market'],
            ['CSO', 'Market'],
            ['HR', 'Market'],
            ['CTO', 'Market']
        ],
        levels: [{
            level: 0,
            color: 'silver',
            dataLabels: {
                color: 'black'
            },
            height: 25
        }, {
            level: 1,
            color: 'silver',
            dataLabels: {
                color: 'black'
            },
            height: 25
        }, {
            level: 2,
            color: '#980104'
        }, {
            level: 4,
            color: '#359154'
        }],
        nodes: [{
            id: 'Shareholders'
        }, {
            id: 'Board'
        }, {
            id: 'CEO',
            title: 'CEO',
            name: 'Atle Sivertsen',
            image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2022/06/30081411/portrett-sorthvitt.jpg'
        }, {
            id: 'HR',
            title: 'CFO',
            name: 'Anne Jorunn Fjærestad',
            color: '#007ad0',
            image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131210/Highsoft_04045_.jpg'
        }, {
            id: 'CTO',
            title: 'CTO',
            name: 'Christer Vasseng',
            image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131120/Highsoft_04074_.jpg'
        }, {
            id: 'CPO',
            title: 'CPO',
            name: 'Torstein Hønsi',
            image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131213/Highsoft_03998_.jpg'
        }, {
            id: 'CSO',
            title: 'CSO',
            name: 'Anita Nesse',
            image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131156/Highsoft_03834_.jpg'
        }, {
            id: 'Product',
            name: 'Product developers'
        }, {
            id: 'Web',
            name: 'Web devs, sys admin'
        }, {
            id: 'Sales',
            name: 'Sales team'
        }, {
            id: 'Market',
            name: 'Marketing team',
            column: 5
        }],
        colorByPoint: false,
        color: '#007ad0',
        dataLabels: {
            color: 'white'
        },
        borderColor: 'white',
        nodeWidth: 65
    }],
    tooltip: {
        outside: false
    },
    exporting: {
        allowHTML: true,
        sourceWidth: 800,
        sourceHeight: 600
    }

});
.highcharts-figure,
.highcharts-data-table table {
    min-width: 360px;
    max-width: 800px;
    margin: 1em auto;
}

.highcharts-data-table table {
    font-family: Verdana, sans-serif;
    border-collapse: collapse;
    border: 1px solid #ebebeb;
    margin: 10px auto;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}

.highcharts-data-table th {
    font-weight: 600;
    padding: 0.5em;
}

.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
    padding: 0.5em;
}

.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}

.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

#container h4 {
    text-transform: none;
    font-size: 14px;
    font-weight: normal;
}

#container p {
    font-size: 13px;
    line-height: 16px;
}

@media screen and (max-width: 600px) {
    #container h4 {
        font-size: 2.3vw;
        line-height: 3vw;
    }

    #container p {
        font-size: 2.3vw;
        line-height: 3vw;
    }
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/sankey.js"></script>
<script src="https://code.highcharts.com/modules/organization.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Organization charts are a common case of hierarchical network charts,
        where the parent/child relationships between nodes are visualized.
        Highcharts includes a dedicated organization chart type that streamlines
        the process of creating these types of visualizations.
    </p>
</figure>