Sending data from html.index to functions.js file

Hello there,

Currently, I am stuck on working with a .html file which needs to send over data to a javascript file with functions. It looks as follows:


let data = [
    ["ID1", "URL1"],
    ["ID2", "URL2"],
    ["ID3", "URL3"],

HTML part calling javascript functions file with

<!DOCTYPE html>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <link href="" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    <title>Metabase Dashboard Carousel</title>
    <script src=""></script>
    <script type="text/javascript" src="./src/carousel.js"></script>
  <body onLoad="createFrames('test!')">
    <button class="btn btn-primary " onclick=autoRun()>Start</button>
    <button class="btn btn-primary " onclick=pause()>Pause</button>

Function which is called

function createFrames(text) {
    let data = prepareFrameSources();
    for(var i in data)        
        prepareFrame(data[i][0], data[i][1]);

Calling the function does give me a print of test! on the .html console with Mozilla inspector. However, running the rest of the script or actually using the data variable as input in the body onLoad function does not work.

  1. How does this come and what would be a fix?

  2. Also, not directly related what is a good way to load files between related .js / .yml / .json as when running the code in .html gives back that require is not defined?

Thanks for the help!

Where is data defined? In your carousel.js?

Does your body tag look like this?

<body onLoad="createFrames(data)">

For the require is not defined problem, sounds like you may be running some back-end/Node code such as…


which doesn’t really work on the browser because it has no knowledge of require. You may want to consider using ES6 modules.