Solved

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

Posted on 2013-12-02
2
29,097 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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.
This article discusses four methods for overlaying images in a container on a web page
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 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…
Suggested Courses

626 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