Setting Value of a filter/dropdown based with Javascript RRS feed

  • Question

  • I need to set the value of this filter based on a querystring. I am using Sharepoint 2013 and this is a portion of code in a Content Editor webpart. I would like to pass the following variable ?type. (ie. Pages/News.aspx?type=[Variable]) The challenge is that the code is getting some options out of a SP list in order to populate the dropdown. Any assistance would be greatly appreciated.

    <div class="news-filters">

    <select class="document-sort" id="newsType" dcnIndex="0">
    <option{{if _xData.NewsCategory==""}} selected="selected"{{/if}} value="all">All Categories</option>
    {{:~choice.getSelectOptions(dcn[0], "NewsCategory", _xData["NewsCategory"])}}


    Monday, June 15, 2015 3:48 PM


  • Hi,

    If you want to set the value of filter based on a querystring, we can use the following jQuery code to get the value from querystring, then set the value to the dropdown list.

    <script src="http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //get type value from URL
            var type = GetQueryStringParams('type');
        function GetQueryStringParams(sParam)
            var sPageURL = window.location.search.substring(1);
            var sURLVariables = sPageURL.split('&');
            for (var i = 0; i < sURLVariables.length; i++) 
                var sParameterName = sURLVariables[i].split('=');
                if (sParameterName[0] == sParam) 
                    return sParameterName[1];

    If I misunderstanding your requirement, please provide more information for further research.

    Best Regards,


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Edited by Dennis Guo Tuesday, June 16, 2015 7:33 AM
    • Proposed as answer by Patrick_Liang Tuesday, June 23, 2015 11:36 AM
    • Marked as answer by Patrick_Liang Wednesday, June 24, 2015 5:21 AM
    Tuesday, June 16, 2015 7:30 AM