Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda