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

91
Views
Is it possible to reuse another function with a javascript file on the browser

In my html file when i click button it will call a function in file home.js.

File index.html:

<body>
   <button onclick="ShowMyAlert()"></button>
<script src="/js/home.js"></script>
</body>

And the funtion will call another function in file cUtilitiesForm.js. File home.js:

 var x = require('./cUtilitiesForm')

 function ShowMyAlert() {
     x.ShowAlertSuccess('Good job')
 }

File cUtilitiesForm.js:

function ShowAlertSuccess(title) {
       Swal.fire(
           `${title}`,
           'success'
       )
    }
module.exports = {
    ShowAlertSuccess: showAlertSuccess,
}

And then I click button it will give a error:

home.js:4 Uncaught TypeError: Cannot read properties of undefined 
(reading 'ShowAlertSuccess')
at ShowMyAlert (home.js:4)
at HTMLButtonElement.onclick ((index):52)

I don't know if this is possible or not

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!