Import Javascript-File - how to use the code?

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
slashmaster
Posts: 29
Joined: Fri May 25, 2018

19 Sep 2018

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.

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

19 Sep 2018

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/

slashmaster
Posts: 29
Joined: Fri May 25, 2018

20 Sep 2018

Hi Alex,
thank you. It works well! :)

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests