{"id":886,"date":"2010-11-28T18:29:20","date_gmt":"2010-11-28T17:29:20","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=886"},"modified":"2015-09-08T20:34:23","modified_gmt":"2015-09-08T18:34:23","slug":"cascading-dropdowns-with-jquery-and-spservices-on-a-page-or-webpart","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/cascading-dropdowns-with-jquery-and-spservices-on-a-page-or-webpart\/","title":{"rendered":"Cascading dropdowns with jQuery and SPServices on a page or webpart"},"content":{"rendered":"<p>The SPServices library on Codeplex (<a href=\"http:\/\/spservices.codeplex.com\/\">http:\/\/spservices.codeplex.com<\/a>) provides a lot of useful functionality to access SharePoint data.<br \/>\nOne of the functions is the SPServices.SPCascadeDropdowns function. Here is a link to the documentation of this function: <a href=\"http:\/\/spservices.codeplex.com\/wikipage?title=$().SPServices.SPCascadeDropdowns&amp;referringTitle=Documentation\">http:\/\/spservices.codeplex.com\/wikipage?title=$().SPServices.SPCascadeDropdowns&amp;referringTitle=Documentation<\/a>\u00a0\u00a0<\/p>\n<p>As explained on the site this function can be used to set up cascading dropdown on SharePoint forms. Repeat: on SharePoint <span style=\"text-decoration: underline;\">forms<\/span>.<br \/>\nSometimes it\u2019s handy to use cascading dropdown lists on a regular page or in a webpart. For this purpose I made a simple jQuery plug-in to provide in this need. The functionality is not that extended as the SPServices.SPCascadeDropdowns, but I\u2019ll guess you get the point.\u00a0\u00a0<\/p>\n<h3>Purpose\u00a0<\/h3>\n<p>The purpose in this example is to make cascading dropdowns with countries and cities. This information is stored in two SharePoint lists and displayed in a Content Editor Webpart on a page.\u00a0\u00a0<\/p>\n<h3>Set up the lists<\/h3>\n<p>Create a list named Countries. \u00a0Fill in some country names in the default Title column.<br \/>\nCreate a list named Cities. Create a lookup column to the Countries list and name the column Country. Do not allow multiple values, the plug-in isn\u2019t ready for that. Fill in some cities and link them to a country.<br \/>\nAdd a document library e.g. with the name ICTLibrary. Of course you are free to choose the names, but be aware of the references in the code in this article, I use the names mentioned here.<br \/>\nUpload three items to this list:\u00a0<\/p>\n<ol>\n<li>jquery-1.4.4.min.js<\/li>\n<li>jquery-SPServices-0.5.8.min.js<\/li>\n<li>jquery.itidea_spcascadingdropdown.js<\/li>\n<\/ol>\n<p>The last file is the plug-in which provides the cascading functionality on a page.\u00a0\u00a0<\/p>\n<h3>Create the cascading dropdownlists<\/h3>\n<p>To create the cascading dropdownlists on a page is quite easy. Just paste the following code to a Content Editor Webpart on a page:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/ICTLibrary\/jquery-1.4.4.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/ICTLibrary\/jquery.itidea_spcascadingdropdown.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/ICTLibrary\/jquery.SPServices-0.5.8.min.js&quot;&gt;&lt;\/script&gt;\r\n\u00a0\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\r\n$(document).ready(function() {\r\n\u00a0\u00a0\u00a0 $('#countries').itidea_spcascadingdropdown(\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 relationshipList: &quot;Cities&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 relationshipParentList : &quot;Countries&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 relationshipParentListColumn : &quot;Title&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 relationshipListChildColumn : &quot;Title&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 relationshipListParentColumn : &quot;Country&quot;,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 childdropdown : &quot;cities&quot;\r\n\u00a0\u00a0\u00a0 });\r\n});\r\n&lt;\/script&gt;\r\n\r\n&lt;select id=&quot;countries&quot; style=&quot;width:150px;&quot;&gt;\r\n&lt;\/select&gt;\r\n&lt;select id=&quot;cities&quot;&gt;\r\n&lt;\/select&gt;\r\n<\/pre>\n<p>There are a few things to know about the options:\u00a0\u00a0\u00a0<\/p>\n<p><strong>relationshipList<br \/>\n<\/strong>The name of the list which contains the parent\/child relationships.\u00a0\u00a0<\/p>\n<p><strong>relationshipParentList<br \/>\n<\/strong>The name of the list which contains the parent items.\u00a0\u00a0<\/p>\n<p><strong>relationshipParentListColumn<br \/>\n<\/strong>The StaticName of the values column in the parent list.\u00a0\u00a0<\/p>\n<p><strong>relationshipListChildColumn<\/strong><br \/>\nThe StaticName of the child column in the relationshipList\u00a0\u00a0<\/p>\n<p><strong>relationshipListParentColumn<br \/>\n<\/strong>The StaticName of the parent column in the relationshipList\u00a0\u00a0<\/p>\n<p><strong>childdropdown<\/strong><br \/>\nThe id of the child dropdownlist\u00a0\u00a0<\/p>\n<p><strong>promptText<\/strong><br \/>\nThe default text displayed in the dropdownlists\u00a0\u00a0<\/p>\n<p>Most of the options are named the same as in the SPServices.SPCascadeDropdowns, because you are probably familiar with these names.\u00a0\u00a0<\/p>\n<p>The cascading dropdownlists are looking like this now when nothing is selected:<br \/>\n\u00a0\u00a0<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingNothingSelected.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-893\" title=\"SPCascadingNothingSelected\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingNothingSelected.png\" alt=\"\" width=\"279\" height=\"48\" \/><\/a>\u00a0\u00a0\u00a0<\/p>\n<p>Countries and all cities are loaded in the dropdownlists:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCountries.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-894\" title=\"SPCascadingShowCountries\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCountries.png\" alt=\"\" width=\"282\" height=\"116\" \/><\/a>\u00a0\u00a0\u00a0<\/p>\n<p><a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCities.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-895\" title=\"SPCascadingShowCities\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCities.png\" alt=\"\" width=\"278\" height=\"148\" \/><\/a>\u00a0\u00a0\u00a0<\/p>\n<p>When a country is selected:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCitiesWhenCountrySelected.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-896\" title=\"SPCascadingShowCitiesWhenCountrySelected\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/11\/SPCascadingShowCitiesWhenCountrySelected.png\" alt=\"\" width=\"277\" height=\"102\" \/><\/a>\u00a0\u00a0<\/p>\n<h3>Summary<\/h3>\n<p>The plug-in is helpful if you want simple cascading dropdown lists on a page or in a webpart with the use of SharePoint data.\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<h3>Download<\/h3>\n<p>Download the plug-in: [download#2] Updated version (November 30 2010; order by was hard-coded on &#8216;Title&#8217; column)<\/p>\n<p>For an extended plugin <a href=\"https:\/\/www.itidea.nl\/index.php\/extended-cascading-with-spservices-and-jquery\/\">check out this post<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SPServices library on Codeplex (http:\/\/spservices.codeplex.com) provides a lot of useful functionality to access SharePoint data. One of the functions is the SPServices.SPCascadeDropdowns function. Here is a link to the documentation of this function: http:\/\/spservices.codeplex.com\/wikipage?title=$().SPServices.SPCascadeDropdowns&amp;referringTitle=Documentation\u00a0\u00a0 As explained on the site &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/cascading-dropdowns-with-jquery-and-spservices-on-a-page-or-webpart\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[11,13,33],"class_list":["post-886","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2007","tag-jquery","tag-moss-2007","tag-spservices"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=886"}],"version-history":[{"count":25,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/886\/revisions"}],"predecessor-version":[{"id":2039,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/886\/revisions\/2039"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}