Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-02
2
Medium Priority
?
30,918 Views
Last Modified: 2013-12-02
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
Comment
Question by:AmbassadorSpock
2 Comments
 
LVL 8

Accepted Solution

by:
Mohit Vijay earned 2000 total points
ID: 39690750
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
 

Author Closing Comment

by:AmbassadorSpock
ID: 39690797
Great....thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question