This project has moved and is read-only. For the latest updates, please go here.

Use SPCascadeDropdowns to select choice field item?

Aug 14, 2010 at 5:56 PM
Edited Aug 14, 2010 at 6:33 PM

So, first things first, I'm a newbie to this.... so please bear with me.

I have an instance where I'm running SPCascadeDropdowns to filter a child lookup field based on a parent lookup field's selection. It works great. What I want to do now is repurpose the code for SPCascadeDropdowns to allow the selection of an item in the child lookup from the previous example to select (not filter) an item in a choice field in the same form. I've written the CAML query for this (which works according to U2U CAML), but where I'm running into issues is figuring out how to change the code to select an item from the choice list based on the query's result, while still allowing the user to select another choice after the code has run (no filtering the field). Any pointers?

Example: I choose "Highrise" from the Parent column, which filters the Child column (using SPCascadeDropdowns). Out of the options in the child column, I choose "Brack". This should auto-select (using what I've named SPCascadeDropdownsChoice) the choice dropdown based on the query I've built (basically, I'm selecting data from the last/previous entry for the child... only one record, though, so I don't have to account for multiple results). The choice dropdown has 0, 4, 7, and 10 as its choices. So it might be autoselected as "4". The user can then change that value as necessary and save the item.

Thanks in advance for any help you can provide!



Aug 14, 2010 at 7:57 PM


Since you're just trying to tie one column's setting to one other column, you probabyly don't need all the complexity of SPCascadeDropdowns, which needs to do a lot to be generalizable. I'd suggest just attaching to the change event in your Brack column and setting the choice dropdown accordingly. My recommendation is to put the business logic (which Brack(s) map to which choice(s)) in a list and read from it using GetListItems, but hardwiring it into your script will work, of course.


Aug 14, 2010 at 10:12 PM

Thanks for the response!

I'm not sure I know how to accomplish what you're describing, but let me give it a shot based on what I can figure out from code snippets:

"attaching to the change event" - Is this all I need to check if the parent field (a lookup column) changed?




So if the column changes, I need to get its value and the value of another column...


TeacherFieldValue = TeacherField.Obj.find("option:selected").text()
SchoolFieldValue = SchoolField.Obj.find("option:selected").text()


And then use them in a query to find the one record I need...

operation: "GetListItems",
async: false,
webURL: ListURL,
listName: ListName,
CAMLQuery: "<Query>
            <FieldRef Name='SchoolField' />
            <Value Type='Lookup'>SchoolFieldValue</Value>
               <FieldRef Name='TeacherField' />
               <Value Type='Lookup'>TeacherFieldValue</Value>
      <FieldRef Name='VisitDate' Ascending='False' />
CAMLViewFields: "<ViewFields><FieldRef Name='" + ChoiceFieldStaticName + "' /></ViewFields>",
CAMLRowLimit: 1,
completefunc: function(xData, Status)

So, given that one result, I need to select the matching value on my choice field (either 0, 4, 7, or 10). This is where I'm getting stuck... I usually figure out how to code based on examples, but I haven't found any. So given the choice column, we'll call it "ChoiceField", and those 4 previously mentioned choices, how would I select the one returned by the query?

Also, is my code logic even sound?

Thanks for the help :)

Aug 14, 2010 at 10:16 PM
It depends on whether you have <20 or 20+ options because SharePoint renders the controls differently in those two cases. If you dig into SPCascadeDropdowns, you'll see how I handle that.

Aug 29, 2010 at 9:27 PM
Edited Aug 30, 2010 at 12:12 AM


I guess where I'm getting hung up is trying to set the "selected" item on the choice dropdowns on the page. I looked in your code and didn't see any hints (although maybe I'm missing something). I've asked this question in a ton of other places, with no response. Is there a specific method or function that you know of (via jQuery maybe) that can set the selected item for a dropdown that already exists on a page (in other words, I'm not creating the dropdown programatically)?

The dropdowns in question will have <10 items in them, if that helps.


Aug 30, 2010 at 7:39 AM


All you should need to do is set the selected attribute on the option element:

.attr("selected", "selected")