Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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…

919 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

12 Experts available now in Live!

Get 1:1 Help Now