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

I have a Knowledge Base template site that I'm trying to customize. I want to create a simple search site, with just two items on it:
- a dropdown menu which displays content of "Keywords" list (from the same site, using the list as its Data Source)
- a "Search" button, that will redirect me to the address:


so that I can easily search by keywords.

I'm used to basic C#, so I was counting on something like "" + dropdownList.SelectedItem.ToString(), but from what I found out it's not going to be that easy.

Somebody told me this can be done using "Content Editor" webpart, but I have no idea how to start.

Is there any way to do it, preferably without involving Visual Studio? I'm kind of used to Sharepoint Designer. :)

share|improve this question
up vote 2 down vote accepted

Using SharePoint designer you can create an HTML Button in the page and on the onClick event execute a JavaScript function that builds the URL by concatenating the site URL and the value of the dropdown menu (Get it using getElementById() and access it's value). Then you can use window.location.href = url to redirect to another page.


<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript">
 function redirectToSearchPage()
    var dropDown = document.getElementById('dropDownClientId');
    var itemText  = dropDown.options[dropDown.selectedIndex].text;
    window.location.href = "http://server/site/_layouts/searchresults.aspx?k=" + itemText;

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

    <asp:DropDownList runat="server" id="ddlKey" DataValueField="Title" DataTextField="Title" DataSourceID="spdatasource1" Width="165px"></asp:DropDownList>
    <input name="Button2" type="button" value="Search HTML" onclick="redirectToSearchPage()" />

share|improve this answer
Hi Moussa, thanks for the reply. Right now I'm trying to familiarize myself with basic JavaScript and get this selected value as string. It's not going well... Tried alert(document.getElementById("ddlKey")); and alert(document.getElementById('<%= ddlKey.ClientID %>'));, as suggested on some sites, but I keep getting a null object. Could you help me some more? :) – Piotr S. Dec 18 '12 at 10:53
Ok. Can you post the code you used for creating the dropdown? – user3470 Dec 18 '12 at 10:57
<asp:DropDownList runat="server" id="ddlKey" DataValueField="Title" DataTextField="Title" DataSourceID="spdatasource1" Width="165px"></asp:DropDownList> – Piotr S. Dec 18 '12 at 11:10
Try adding ClientIDMode="Static" to the dropdown and use document.getElementById("ddlKey"). – user3470 Dec 18 '12 at 11:23
Ok the final solution is to browse to the SharePoint page and view the html source. locate the ddlKey dropdown and get its id. Use this id in JavaScript. – user3470 Dec 18 '12 at 12:53

Final solution, thanks to Moussa: onClick event:

var id = 'ctl00_m_g_f9ae17e4_a205_4c1c_88c1_300f89d385b3_ddlKey';
window.location = "http://server/site/_layouts/searchresults.aspx?k=" 
    + document.getElementById(id).options[document.getElementById(id).selectedIndex].text;`

All in one line. Element ID od ddlKey dropdown found in the webpage source.

share|improve this answer
I have added an example that can help you better organize your code. – user3470 Dec 18 '12 at 13:44
Nice, thanks. I thought I need to make it into one line. :) – Piotr S. Dec 18 '12 at 13:46

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.