03.11.2010 Updated the code to eliminate the need to refer other external resources than jQuery. Removed the argument “lookupSourceListURL” from the function call.
The code is tested in IE, Chrome and Firefox. Opera is not supported.
NOTE: When updating existing script you must modify the function call and remove the argument “lookupSourceListURL”.
I have previously posted a solution for creating cascading dropdowns from SharePoint single line text fields. Populated based on a query against another list.
I have reviewed the script to add a few enhancements.
- No more need to create a calculated column in the “lookup list”
- Less arguments to pass to the function – sleeker code
- Overcomes a possible bug regarding the previous version using “BeginsWith” rather than “Eq” to match the items
This release (as the previous) has these features:
- “Converts” standard SharePoint single line text fields to dropdowns
- Uses the converted SharePoint single line text fields to hold the values
- Populates the dropdowns by querying any SharePoint list or library
- Dynamically fills or clears the hidden fields holding the selected value to adapt to changes in the selections – thus preventing “impossible combinations”
- Preserves selections during page refresh due to form validation
- Reads back and fills the dropdowns if used in EditForm
As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”). Upload jQuery and the file “spjs_CascadingDropDowns_v2.js” to that library.
The jQuery-library is found here. The sourcecode refers to jquery-1.4.2.min. Some of the functions are not supported in previous releases.
The sourcecode for the file “spjs_CascadingDropDowns_v2.js” can be found below.
You can pull any values from another list – an example provided below.
Source list:

The field “Make” is the native “Title” field.
The CEWP code – place below the Form:
<script type="text/javascript" src="/test/English/Javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/test/English/Javascript/spjs_CascadingDropDowns_v2.js"></script>
<script type="text/javascript">
// Use the FieldInternalName and not the Displayname.
providerArr = ['Title','carModel','carColor','carInterior','carMilage'];
consumerArr = ['Title','Model','Color','Year','Milage'];
cascadingDropDowns_v2(providerArr,consumerArr,'{83eb224b-03fa-4a8b-b493-80253373a962}','<select>',5,true,false);
</script>
Parameters explained:
- providerArr: Array of FieldInternalNames of the fields in the source-list
- consumerArr: Array of FieldInternalNames of the fields in the list where the dropdowns will be created
- lookupSourceListGuid: GUID of the source-list
- dropDownDefaultvalue: The default value of dropdowns that are not empty – ex. <select>
- numberOfDropdowns: Number of levels of cascading dropdowns – (2-5)
- debug: true or false – if true: the textfield that holds the dropdownvalue is visible and some alerts are displayed
The code for the file “spjs_CascadingDropDowns_v2.js” can be found here
How to use these scripts in a customized form
Ask if anything is unclear.
Alexander

March 15, 2011 at 5:00 pm |
Hi Alex,
I have your cascading drop down controls on an upload doc form after the user selects a document they then specify some meta-data that utilizes your solution. It works the majority of the time but every now and then on specific files it defaults the first drop down list with a value instead of letting the user select it. This is not that big of a deal in of itself but it somehow breaks everything after the user selects the right fields and tries to upload. They then get an error and I can’t figure what is wrong
March 16, 2011 at 5:24 pm |
I have the applied the code with below script
// Use the FieldInternalName and not the Displayname.
providerArr = ['Title','Task'];
consumerArr = ['Title','Tasklist'];
cascadingDropDowns_v2(providerArr,consumerArr,’{E46DF04E-EC51-4F2B-A7AD-DCC166291D0E}’,”,2,true,false);
however feild are not gettign converted to drop down and also it shows a message ” Please wait while scripts are loaded
Can u pls help
March 16, 2011 at 5:26 pm
// Use the FieldInternalName and not the Displayname.
providerArr = ['Title','Task'];
consumerArr = ['Team','Tasklist'];
cascadingDropDowns_v2(providerArr,consumerArr,’{E46DF04E-EC51-4F2B-A7AD-DCC166291D0E}’,”,2,true,false);
March 17, 2011 at 12:31 pm |
I fixed my above issue however i got a new one , sorry to trouble you more , Can you please advise why i am getting new error as “The fieldname specified as “consumerArr Nr1″ does not exist. You must use “FieldinternalName” to identify the fields”
I have crossed check twice or thrice on the code however still the problem persit
<script type="text/javascript" src="/sites/infyetd/WebDoc/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="/sites/infyetd/WebDoc/spjs_CascadingDropDowns_v2.js"></script> <script type="text/javascript"> // Use the FieldInternalName and not the Displayname. providerArr = ['Title','TaskN']; consumerArr = ['Title','TasklistS']; cascadingDropDowns_v2(providerArr,consumerArr,'{E46DF04E-EC51-4F2B-A7AD-DCC166291D0E}','<select>',5,true,false); </script>March 17, 2011 at 4:03 pm
Hi,
From the error message i would guess that ‘TasklistS’ is not the correct FieldInternalName. FieldInternalName’s are case sensitive so please check it a forth time
Alexander
March 17, 2011 at 4:08 pm
Sorry, my mistake
consumerArr Nr1 would be “Title”…
This is a “built in” field and should be correct. Is the list modified in any way?
Alexander
March 23, 2011 at 6:12 pm
No, Not at all.
I tried doing it again with new list and i am getting the same error
February 1, 2012 at 7:43 am
I have the same problem explained by Vinay. I am getting the same error “The fieldname specified as “consumerArr Nr1″ does not exist. You must use “FieldinternalName” to identify the fields”
It is working fine in 2007 but not on 2010. Any help would be greatly appreciated. Alex any thoughts?
February 10, 2012 at 12:06 am
Hi,
What kind of list is it you are trying to use it with?
Alexander
March 29, 2011 at 5:59 pm |
Playing with tis script I am trying to use a people picker at the end of the the DD. It is not the result I am looking for, but it does populate a dropdown with the poeple picker information from the sourcelist poeple picker field. Is there something that can be easily changed to allow for the use of a people picker field on the target list?
March 30, 2011 at 9:44 pm
Hi Larry,
This script deals with text-fields only. You could however use another script in PreSaveAction() to populate the real people picker based on the cascading dropdown value.
Alexander
April 13, 2011 at 9:53 pm |
bugging you again. I know this script hides the original fieldsand displays the dropdowns. If I wanted to set the first dropdown value, from a query string value. Is it possible without modification to the original script?
April 13, 2011 at 11:05 pm
Yes, just set the underlaying text filed to a valid choice before calling the cascading dropdown script. It will pick up the value in the text field and preselect it.
Alexander
May 4, 2011 at 8:50 pm |
Do you have any information on how to use PreSaveAction()? I have would like to create a cascading drop down with the first dropdown (department) as a regular text box and the second a people picker that automatically populates the manager’s name for each department.
Thanks!
May 6, 2011 at 8:43 pm
Hi,
If present, the function PreSaveAction is executed before save on both NewForm and EditForm in SharePoint.
The content you put in the function is up to you. I do not think there are more to say about it?
Alexander
June 6, 2011 at 10:59 pm |
This code works awesome! Is there anyway to manipulate it so that after the first dropdown is chosen it will automatically choose the other two instead of defaulting to select?
The way my site is designed is that you chose a person’s name then their managers will populate 2 cascading dropdowns. Each person will always have the same managers that populate.
Thanks!
August 3, 2011 at 10:02 pm
Hi,
Sorry for the late reply. This solution can not do that as it uses single line of text fields only. It is possible to create such solution, but i do not think i have anything like this posted.
Alexander
July 2, 2011 at 10:03 am |
Hi Alexander,
I need your help again. What would I need to change in this script to populate a editform with column data from another list based on a lookup.
So I have one list with lots of columns [Field1, Field2, Field3..] and a second list with the same columns plus a lookup linked to the first list. When the lookup is selected the edit form is populated with the data from the first list.
Thanks again
Tom
August 3, 2011 at 9:59 pm
Hi,
This solution will not do what you want, but i have done something similar earlier. Take a look at this one and see what you get out of it.
Alexander
August 19, 2011 at 7:29 am |
Will this script work with SharePoint 2010?
August 19, 2011 at 10:40 am
Yes,
Alexander
August 25, 2011 at 7:43 pm |
Is it possible to default to a value by location in the list
September 14, 2011 at 10:22 pm
Not quite sure what you want, but if you insert a valid value into the text field before calling the “cascading dropdown code”, the value will be picked up.
Alexander
September 14, 2011 at 7:59 pm |
for some reason the edit form does not update, it displays and I can make chnages but it does apply the changes to the text field?
September 14, 2011 at 9:58 pm |
Well tried to copy code but didnt work, anyways the code works on newform like a charm but on edit form it displays the drop down and works as advertised but does not store value……
September 14, 2011 at 10:21 pm
Hi,
Set the debug parameter to true and see if the field updates.
Alexander
October 8, 2011 at 11:49 pm |
Hi!
I have used your script. It helped me in my job. But I have a question: can I use my first value as a default?
October 9, 2011 at 2:54 pm
Hi,
Yes, set a default value for the first column in the list settings. As long as this is a valid choice, the dropdown should pick it up.
Alexander
January 12, 2012 at 11:46 pm |
The link for the spjs_CascadingDropDowns_v2.js JQuery is not working. Could you please post the working JQuery link or email me the JQuery ?
Thanks
1MT
January 13, 2012 at 12:01 am
jQuery is found here: http://jquery.com/
Note that you must use v1.6.4 or below due to an incompatibility issue with v1.7x
Alexander
January 13, 2012 at 12:31 am |
Hi Alexander,
Thanks for the reply. I got the JQuery from jquery.com for Jquery version v1.6.4 but what i meant to ask was the link where code for file “spjs_CascadingDropDowns_v2.js” could be found is not working.
The hyperlink to the following is not working in your article.
“The code for the file “spjs_CascadingDropDowns_v2.js” can be found here.”
So could you lease email me the code so that i could create the spjs_CascadingDropDowns_v2.js file.
Thanks
1MT
January 13, 2012 at 12:37 am
Hi,
There should have been a redirect from the old server to the new… I have updated the link.
Alexander
February 16, 2012 at 5:57 pm |
hey A,
have a question about this script. I have a unique scenario where it goes 4 levels down. at the fourth level I have 4 different fields, but all four of them should be filterd by the third field. the all four fields at the fourth level pull the same data, but when I try to add the script a second time it replicates the dropdowns.
is there a way to have it work like
field1 filters field2
field2 filters field3
field3 filters field4,field5 ,field6, field7
February 19, 2012 at 11:51 pm
This is not possible using the “out of the box solution”, but it is possible using another script to pull the four parallel dropdowns separately based on the selection in the last “cascading dropdown”.
It would have to be custom made though.
Alexander
February 28, 2012 at 9:01 pm |
Hey A,
I figured it’s about time to bug you one again. I have implemented this script on a SP 2010 discussion board. NewForm, works great, EditForm, works great. When User clicks reply, the cascade works perfectly, but the dropdowns are not populated. Is there something I can do or add to get this value set to what was selected on the NewForm, like the editform works?
February 28, 2012 at 10:04 pm
Like this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="http://spjsfiles.com/SharePoint%20JavaScripts/spjs-utility/28.02.2012/spjs-utility.js"></script> <script type="text/javascript"> var arrOfFieldsToSet = ['Level1']; ExecuteOrDelayUntilScriptLoaded(getValuesfromParent, "sp.js"); function getValuesfromParent(){ var pid, item; pid = GetUrlKeyValue('DiscussionParentID'); if(pid!==''){ item = spjs_getItemByID({listName:_spPageContextInfo.pageListId,id:pid,viewFields:arrOfFieldsToSet}); if(item!==null){ $.each(arrOfFieldsToSet, function(i,fin){ setFieldValue(fin,item[fin]); }); } } // Call "Cascading dropdowns" here } </script>Put this code in NewForm.aspx and change the array “arrOfFieldsToSet”
Note that you have to update spjs-utility.js – I have linked it directly from my download site, but I recommend you download the file locally.
Alexander
March 7, 2012 at 11:50 pm |
I am using the cascading dropdown code on one of my sites and I am getting the following script error: ‘consumerArr.1′ is null or not an object
I am referencing the most recent version of the cascading dropdowns code and using jquery 1.6.4-min.js
My form is not custom.
Have you every seen this error before?
Thanks
March 7, 2012 at 11:55 pm
also i have sharepoint 2007
March 27, 2012 at 11:20 pm
I’m having the same issue. After selecting from the first dropdown then the error shows. I am using 2007 and have only 2 dropdowns. I have tried jquery 1.6.4 and 1.7.1 to no avail….
Alex, can you please at least look into this?
April 21, 2012 at 8:56 am
Hi,
Sorry for the late reply. I have a few questions:
Do you have other scripts in the same form? – if so there might be a conflict with other code. Could you try removing all other scripts to test?
Which browser are you using?
Alexander
April 19, 2012 at 2:04 pm |
Hi every one ,
i have Created two Lists (Custom Share point list)
List1 and List2, List1 is Having columns ProductName and Supplier both (single line of text)
Similarly
List2 has ProductName and Supplier as Lookups columns of List 1 respectively
I have created javascript code as follows:
————————————————————————————-
// Use the FieldInternalName and not the Displayname.
providerArr = ['Title','ProductName','Supplier'];
consumerArr = ['Title','ProductName','Supplier'];
cascadingDropDowns_v2(providerArr,consumerArr,’{eec99d33-8a4b-4a3e-8c9c-fd7333d7c8df}’,”,2,true,false);
————————————————————————————-
Have changed the GUID for the resource List ,
But the system is showing some error :
“The fieldname specified as “consumerArr Nr1″ does not exist.
You must use “FieldInternalName” to identify the fields.”
Many thanks Alexander
April 21, 2012 at 8:58 am
Could you try using another field as “consumerArr Nr1 (Not the “Title” field)?
Alexander
May 13, 2012 at 3:13 pm
It works if you dont use Title in the arrays in SharePoint 2010…
May 16, 2012 at 6:31 pm |
Looks like with SharePoint 2010 if you have the Silverlight capabilities enabled this script won’t work – the javascript loads when the page loads, and the edit controls aren’t there for it to hook. When you click “edit” to open the edit form, the javascript is already dead, so it doesn’t run.
May 16, 2012 at 6:36 pm
Hi, What do you mean by “Silverlight capabilities”? is it the opening in a modal dialog?
Alexander
May 21, 2012 at 10:15 am |
Hi Alexander,
Great solution , I got it working in 1st attempt
Although-
I tried having two different source lists for two dropdowns each using 2 CEWPs…One works , but the other doesnt show its cascading dropdown. any idea how i can make it to work?
if i toggle the positions of the CEWPs the bottom most doesnt work…