Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda