I have two Text filter web parts (Project and Customer Name) with Apply Filters button for one list. There is a SPServices.SPAutocomplete on each and it works great. Now, I want to show the values in the second filter's autocomplete based on selected value of the first one so I'm using a dynamic CAMLQuery.

The problem is that it simply is not working. I tried it with the static CAMLQuery value and it works. Based on other people's questions here on Stack, and tons of other examples, I saw it can be done dynamically. I suspect the problem hides in the time of call of the autocomplete, but I don't have that much JS / Jquery background. Does it load on document.ready only and ignores all the variables after?

Here is my snippet, it is inside the $(document).ready(function() {} as well as other code. Any help is much appreciated.

var projectName;
var camlQuery;
document.getElementById('Customer_Name_Filter_Id').onclick = function(){
    projectName = document.getElementById('Project_Name_Filter_Id').value;
    camlQuery = "<Eq><FieldRef Name='Title'/><Value Type='Text'>"+projectName+"</Value></Eq>";

    sourceList: "{7DEBDF67-3DBE-4D57-BD09-E9CE7B60A09E}",
    sourceColumn: "Customer",
    columnName: "CustomerNameFilter",
    CAMLQuery: camlQuery,
    filterType: "Contains",
    highlightClass: "ms-bold",
    uniqueVals: true,
    ignoreCase: true,
    numChars: 3,
    slideDownSpeed: "fast",
    debug: true


I tried to put the $().SPServices.SPAutocomplete inside the .onclick function, and a couple of other JS events and after this, the filter WP just froze and could not be typed in.

  • The CAML query looks malformed, it should be wrapped in a <Query></Query> tag Sep 26, 2013 at 20:00
  • @PirateEric It is :) Like I said, it works for static CAML values. Also, the official SPServices documentation states that it's just <Eq></Eq> needed.
    – dzookatz
    Sep 27, 2013 at 7:08

1 Answer 1


As I understand it, on pageload you populate the first AutoComplete with values to choose between. And then when you have selected a value from the AutoComplete you want to populate another AutoComplete (for another field) with new values based on the selected value from the first AutoComplete.

You need to implement functionality that will trigger and call $().SPServices.SPAutocomplete with the new CAMLQuery to populate the new AutoComplete for the second field when a value is selected from the first AutoComplete.

  • Okay, but I also tried to put $().SPServices.SPAutocomplete under .onclick event, and there is absolutely no response from the filter - it won't even let me type anything.
    – dzookatz
    Sep 26, 2013 at 13:41
  • @dzookatz Try changing the onclick to onchange instead.
    – user2536
    Sep 26, 2013 at 13:44
  • I think I tried every single event from JS and Jquery library I could find :) Filter does not work at all on .onchange...
    – dzookatz
    Sep 26, 2013 at 13:47
  • @dzookatz Please join me in chat.stackexchange.com/rooms/10766/daniel-ziga-and-dzookatz
    – user2536
    Sep 26, 2013 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.