1

My list categories:

  • Cats
  • Dogs
  • Cats and Dogs

What i want to achieve: If 'Cats' is ANYWHERE mentioned in the list field, display data in HTML table. This means category

  • Cats
  • Cats and Dogs

will appear in the HTML table.

<SCRIPT type=text/javascript> get() ;function get() { var method = "GetListItems";                
var webURL =  $().SPServices.SPGetCurrentSite() ;                    
var list = "Animal Zoo";
var value = "Cats";                   
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
var query = "<Query><Where><Eq><FieldRef Name='Category' /><Value Type='Text'>" + value + "</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>"; 
</OrderBy></Query>";                  

$().SPServices
({ operation: method, async: false, webURL: webURL, listName: list,
CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQuery: query, completefunc: function (xData, Status)
{ $(xData.responseXML).SPFilterNode("z:row").each(function()
{ var title = $(this).attr("ows_Title");
var update  =  $(this).attr("ows_Update");
var date  =  $(this).attr("ows_Date");

$("#myDataTable").append("<tr align='middle'>" +
"<td align='left'>"+date+"</td>" + "<td align='left'>"+update+"</td>" + "</tr>");

}); } }); };
</script>
4

You should use <Contains> instead of <Eq> in your caml query:

var query = "<Query><Where><Contains><FieldRef Name='Category' /><Value Type='Text'>" + value + "</Value></Contains></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>"; 
</OrderBy></Query>";

More on <Contains> element can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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