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

206
Views
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 answers
Answer question

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 Report

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 Report
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!