I would like to call a javascript function in an external JS file, using the onClick
function on a button in this file, form.tmpl.htm
.
<button type="button" value="Submit" onClick="Call the external js file" >
The javascript file is in Public/Scripts/filename.js
. I have a template file in template/form.tmpl.html
. The root folder contains the Public
and template
folders.
This question is related to
javascript
I have to agree with the comments above, that you can't call a file, but you could load a JS file like this, I'm unsure if it answers your question but it may help... oh and I've used a link instead of a button in my example...
<a href='linkhref.html' id='mylink'>click me</a>
<script type="text/javascript">
var myLink = document.getElementById('mylink');
myLink.onclick = function(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "Public/Scripts/filename.js.";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
}
</script>