Posted on:
Categories: SharePoint
Description: Updates to Lookup List rendering in SharePoint 2013, setting the selected value using jQuery requires updates from SharePoint 2010
A client was recently migrating from SharePoint 2010 to 2013 and discovered some issues with a jQuery script. The purpose of the script was to set the selected value of a dropdown list with a value that was passed in from a query string. The dropdown list was a Lookup list. A quick google search brought up a number of helpful sites that explained in detail how to do this… In SharePoint 2010… Here's my favourite, Setting SharePoint Lookup Lists w/ jQuery (+/- 20 items)What Happens in 2013? It looks like how the Lookup list gets rendered in SharePoint 2013 has changed again. We no longer have to deal with the "do I have more or less than 20 items" issue. The rendering is the same regardless. For comparison, let's take a look…SharePoint 2010 (less than 20 items) SharePoint 2010 (20 or more items) SharePoint 2013 All this means is that you no longer need to check to see if there are more than 20 items in the Lookup list. But it also means that if you were doing this previously in SharePoint 2010, you will need to update your jQuery for 2013.Putting it Together Here is a sample jQuery function to set the selected value of a Lookup list function setSelectedValue(fieldTitle, lookupVal) $("select[title='fieldTitle']").val(lookupVal);