Page 1 of 1

Import Javascript-File - how to use the code?

Posted: 19 Sep 2018
by slashmaster
Hello,

i want to use an central JavaScript-File for different forms.
I add an html-control to the form with this code:

Code: Select all

<script language="javascript" type="text/javascript" src="../javascript.js"></script>
the code from "javaScript.js" is

Code: Select all

alert("hello world");
$('#fd_form').append('it work's!!');
If i run the Form the first line works well and the second not. If i set the same code into the JavaScript-Editor SP-Forms both lines works well. How can i speak to my controls, with an extern Javascript?

thanks in advanced.

Re: Import Javascript-File - how to use the code?

Posted: 19 Sep 2018
by AlexZver
Hi,

If you want to use jQuery and fd variables in a separate JS-file, you should declare them globally in the JS-editor:
window.$ = $;
window.fd = fd;

And then load your custom JS with $.getScript():
https://api.jquery.com/jquery.getscript/

Re: Import Javascript-File - how to use the code?

Posted: 20 Sep 2018
by slashmaster
Hi Alex,
thank you. It works well! :)