Site name in SharePoint cascading dropdown functionality
-
08-02-2021 - |
Question
I am a SP Admin and new to coding. From the below script, i am not sure what should i keep as my site name. I am placing that script in content editor web part in the site https://sharepoint.com/sites/sitecollection. According to this site, what should be my url from the below script be?
i tried to use cdn links SP Services, but the script is not loading, it says the script is not safe.
<script src="https://site name/jquery.min.js"></script>
<script src="https://sitename/jquery.SPServices.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$().SPServices.SPCascadeDropdowns(
{
relationshipList: "Employee",
relationshipListParentColumn: "Company",
relationshipListChildColumn: "Title",
parentColumn: "Company",
childColumn: "Employee",
debug: true
});
});
</script>
Solution
You could use the following link:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.6.2/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.6.2/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function ()
{
$().SPServices.SPCascadeDropdowns(
{
relationshipList: "Employee",
relationshipListParentColumn: "Company",
relationshipListChildColumn: "Title",
parentColumn: "Company",
childColumn: "Employee",
debug: true
});
});
</script>
OTHER TIPS
I don't see 'folder name' part in URL provided by you.
Follow next steps to upload JS files on your site in order to be able to use these scripts:
- Visit your site - https://sharepoint.com/sites/sitecollection
- Click on Site contents > Site Assets
- Upload JS files to Site Assets folder(or any other document library)
- Open web page(or list form) where you want to use scripts
- Add new Script Editor Web Part(or Content Editor Web Part)
Add your code
<script type="text/javascript" src="/sites/sitecollection/SiteAssets/jquery.min.js"></script> <script type="text/javascript" src="/sites/sitecollection/SiteAssets//jquery.SPServices.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $().SPServices.SPCascadeDropdowns( { relationshipList: "Employee", relationshipListParentColumn: "Company", relationshipListChildColumn: "Title", parentColumn: "Company", childColumn: "Employee", debug: true }); }); </script>
If you are prefixing src url with https://
then it needs to be the full absolute url (https://sharepoint.com/sites/sitecollection), if you want to use a server-relative url in case your server name changes, then do not use the https://
protocol prefix.
For example: <script src="/sites/sitecollection/SiteAssets/jquery.min.js"></script>