Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting up a JS file to get its function triggered

I’m learning JavaScript and in a few scripts that I have come across I can see a reference to what seems like apis and then functions. For example:

      // Call the what3words
      what3words.api
        .gridSectionGeoJson({
          southwest: {
            lat: sw.lat,
            lng: sw.lng
          },
          northeast: {
            lat: ne.lat,
            lng: ne.lng
          }
        })

I’ve tried to replicate this by swapping this code out for my own version by doing the following:

  1. Remove what3words.js
  2. Include my own script file script.js in the headers for that page
  3. Include a function inside that file, such as this:

function gridSectionGeoJson() {
  document.getElementById("demo").innerHTML = "Hello World!";
}

However this never gets triggered. How do I setup my script.js so that my function gets triggered by the code in the top snippet? I imagine that has to do with the reference to “what3words.api” that I need to somehow designate inside my own JS file to get it to trigger.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In the script block above you would just call gridSectionGeoJson(); given the script you have above. You typically want to include all scripts at the end of the page when possible.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading