• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 32723
  • Last Modified:

Use HTML Button OnClick to call a JavaScript function in another file

How do I include an external JavaScript file so that a HTML Button OnClick has access to it?

Please provide an example.

Thank you
0
AmbassadorSpock
Asked:
AmbassadorSpock
1 Solution
 
Mohit VijayCommented:
assume you have a javascript file called myfile.js @ the root of application

so you have to give ref. of that fine in head tag of html

<script src="~/myfile.js"></script>

now in this myfile.js, you can write a function that will be called on click on html button. assume the function name is buttonClicked

so in js file, you can write

function buttonClicked()
{
alert('button click called');
}

And for html button you can write

onclick="javascript:buttonClicked();"
0
 
AmbassadorSpockAuthor Commented:
Great....thank you
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now