SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my snippet code here.I'm getting some column values from shrepoint list to a dropdpwnlist.But i would like to append the values to a url when an option is selected. So thayt i can use it to filter a list as a parameter. The problem i have is after i select an option and the pages url changes and appends a value to the URL the value i selected isn't set to what i selected but goes back to "select" the default value.

<select id="Phones">

<option value="Select">select</option>
<option value="Alcatel">Alcatel</option>
<option value="BlackBerry">BlackBerry</option>
<option value="HTC">HTC</option>
<option value="Huawei">Huawei</option>
<option value="LG">LG</option>
<option value="Motorola">Motorola</option>
<option value="Nokia">Nokia</option>
<option value="Samsung">Samsung</option>
<option value="Sony">Sony</option>

// Set the onchange event for the new dropdown
$("#Phones").change(function() { checkSelected(); });

// Run the onchange event to perform any default actions necessary

function checkSelected() {
// You could use the value of the dropdown in another SPServices request
// here or just perform some other code

 var m = $('#Phones').find("option:selected").val();
 if (m !== 'Select')

 var url = "/m.aspx?m=" + m;
 window.location = url;
//Tried selecting the selected value here but doesn't work



share|improve this question

The problem is that when you assign to windows.location a new instance of the page is loaded, so anything that happened on the old is forgotten

So you need to check for the query string parameter on load of the page and use it to set the select (before you attach your event handler)

By the way you should always use jQuery in noConflict mode when using it on a system which includes other javaScript libraries which use $ (like ASP.NET AJAX which SharePoint loads)

share|improve this answer

Is the select option default of course. Why don't you use jQuery Cookie (see here or the Javascript session variables (see here to store the currently selected value and restore it upon reload, instead of head-banging to read the Query String, which we know it all, with SharePoint it never get's easier, but on contraire!

Hope it helps, C:\Marius

share|improve this answer

This is my fix. I used the below to get the Querystring parameter:

<script type="text/javascript">
function getParameterByName(name)
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(;
  if(results == null)
    return "";
    return decodeURIComponent(results[1].replace(/\+/g, " "));

and then

 $("#Phones option").each(function(){

   var b = $(this).text();

   var a = getParameterByName("s");
        //alert(a + " - " + b);
       //Check to see if the querystring param equals the each of the options 
        $("#Phones  option[value='" + a + "']").attr("selected", "selected")



share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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