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

208
Vistas
JS onclick function passing external file

I have a menu which is plain HTML In there I have some images. When you click on those an action should be preformed (for example opening or closing the menu). This plain HTML menu is included by PHP.

To preform an action, I thought adding the JS onclick="" tag to my HTML would be a good idea. Now I have created some .js files that are in a subdirectory called js.

Now is my question how to pass the .js files located in the subdir to the onclick="" tag.

(TLDR)

/index.php <- there is the navigation bar inside

/js/file.js <- want to access this file via onclick="" in index.php

How can I do that

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

All you have to do is to put this <script src="/js/file.js"></script> before your </body> tag (or footer if you want) then call the functions inside with onclick or onload event. Provide more details if you need more clarification.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you're trying to access some JavaScript in an external file, just include that file in your index.php like this.

<script src="myscripts.js"></script>

Then you can call your JavaScript functions in the "onclick" method as if it was written on the same page.

onclick="yourMethod()" //your method name here 

Check this out: https://www.w3schools.com/tags/att_script_src.asp

about 4 years ago · Juan Pablo Isaza Denunciar
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