Tuesday, January 4, 2011

Cascading Drop down In SharePoint Lists using jQuery

Out-of-the-box SharePoint doesn't provide a way to cascade drop downs in list forms. Luckily, jQuery provides a way to implement cascading drop downs in SharePoint list forms. Here is the step by step implementation guide:

We need to have two more lists to implement this. Lets say:

List 1: Parent list, say: Country

cascading drop down sharepoint

List 2: Child list, say: Cities
cascading dropdown sharepoint list

List 3: Our target list, where we are going to implement the Cascading drop down.

So, Now:

1. Download the jquery-1.3.2.min.js by Jquery.com, from the below link
 http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js

2. Download spservices (jquery.SPServices-0.5.6.min.js) from the codeplex link
http://spservices.codeplex.com/

3. After downloading upload these two files in a document library

4. In SharePoint Designer, create your own NewForm.aspx (and EditForm.aspx)

Insert the following code: Just below
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script language="javascript" type="text/javascript" src="/address to document library/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/address to document library/jquery.SPServices-0.4.8.min.js"></script>
<script language="javascript" type="text/javascript">
 $(document).ready(function() {
  $().SPServices.SPCascadeDropdowns({
   relationshipList: "Cities",
   relationshipListParentColumn: "Country",
   relationshipListChildColumn: "Title",
   parentColumn: "Country",
   childColumn: "City",
   debug: true
  });
 });
</script>

Here:
  • relationshipList: “Cities” : this is the name of the relationsship list = the list containing parent and child
  • relationshipListParentColumn: “Country” : Column name from the Cities list
  • relationshipListChildColumn: “Title” : Column name from the Cities list
  • parentColumn: “Country”: Column name from the list where the drop down is = Vacation Plans
  • childColumn: “City”: Column name from the list where the drop down is = Vacation Plans

Demo: http://www.sympraxisconsulting.com/Demos/Demo%20Pages/CascadingDropdowns.aspx

Cascading drop down example- What you will get as output is:
Cascading Drop down in SharePoint List Forms using jQuery
Verified that, cascading dropdown list method works on both SharePoint 2007 and SharePoint 2010



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

9 comments :

  1. Really love how everyone puts up this example but does not include the part after on how to get that value into the SharePoint list. This example only gives you the cascading drop down and does not populate the actual SharePoint list.

    ReplyDelete
  2. How fabulous this is, thanks for sharing, as for the last comment if you go to the website which its linked to you can see it in action and imitate this, thanks for this snippet of useful info
    Kris

    ReplyDelete
  3. Why does this script make customized button redirects no longer work?

    ReplyDelete
  4. The script works fine except when clicking on Submit button I get an unexpected error page...

    ReplyDelete
  5. Hi ,I want to perform cascading among 4 fields in a nintex form.Can u help me.

    ReplyDelete
    Replies
    1. Nintex has published a white-paper on this: http://connect.nintex.com/files/folders/tutorials_and_how_tos_nf2010/entry20327.aspx

      Delete
  6. Any suggestions on how to populate a 3d level cascading dropdown that has values based on teh 1st and 2d dropdowns? Marc Anderson said that SPCascade Dropdown CAML query won't work for this instance.

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...