Solved

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

Posted on 2013-12-02
2
26,253 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now