Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Calling function from seperate JavaScript file

Before writing this question I read Can we call the function written in one JavaScript in another JS file? and Calling a JavaScript function in another js file but still cannot fix my issue.

I am getting the error message - Uncaught ReferenceError: getLocaleDateString is not defined.

The file that contains the function is being loaded before the file that needs the function.

When I copy the contents of getLocaleDataString.js into sys.datepicker.js everything works fine, but the code then starts to look messy and is hard to navigate.

reigster4.html

<body>
    <script src='{% static "getLocaleDateString.js" %}'></script>
    <script src='{% static "sys.datepicker.js" %}'></script>
</body>

getLocaleDataString.js

    (function ($) {



  function getLocaleDateString() {

 
    const formats = {
          "af-ZA": "yyyy/MM/dd",
          "zu-ZA": "yyyy/MM/dd",
    };

    return formats[navigator.language] || "dd/MM/yyyy";
  } //end of getLocaleDateString


  
})

sys.datepicker.js

 function formatDate(year, month, day) {
    let str = (navigator.language, getLocaleDateString());

    return(str)
  
  } 

Update - getLocaleDataString.js

I changed the code to this

  function getLocaleDateString() {


const formats = {
      "af-ZA": "yyyy/MM/dd",
      "zu-ZA": "yyyy/MM/dd",
};

return formats[navigator.language] || "dd/MM/yyyy";


} //end of getLocaleDateString

Simply commenting out the rouge code did not work. I had to physically delete it.

Now everything is working correctly.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!