SharePoint - SharePoint dropdown with redirect

Asked By Chester Thomas on 28-Oct-11 11:36 AM
I have a dropdownlist   <SharePoint:DVDropDownList AutoPostback="true" runat="server" id="drop" selectedvalue="Select..." datasourceid="spdatasource1" datatextfield="Title" datavaluefield="URL"/>
which has all its items generated from a list which is fine. I however need to get the user to be redirected to another page when a different selection is made, it should redirect to another page.

I need this to be done by javascript or code. All my content is in a <asp:content> page. Hope it makes sense and please help experts!
dipa ahuja replied to Chester Thomas on 28-Oct-11 11:49 AM
Try this:

<script type="text/javascript">
function ch1() {
  var ddlReport = document.getElementById("<%=DropDownList1.ClientID%>");
  var Text = ddlReport.options[ddlReport.selectedIndex].text;
  var Value = ddlReport.options[ddlReport.selectedIndex].value;
  if (Value != "Select") {
    window.open("Page2.aspx?id="+Value);
  }
}
</script>

Chester Thomas replied to dipa ahuja on 29-Oct-11 02:03 PM
I can see the postback trying to do something but it is not firing the event. Where must I place the javascript code?
dipa ahuja replied to Chester Thomas on 29-Oct-11 02:12 PM
<script type="text/javascript">
function ch1() {
  var ddlReport = document.getElementById("<%=DropDownList1.ClientID%>");
  var Text = ddlReport.options[ddlReport.selectedIndex].text;
  var Value = ddlReport.options[ddlReport.selectedIndex].value;
  if (Value != "Select") {
    window.open("Page2.aspx");
  }
  //alert(Value);
}
</script>

<asp:Button ID="Button1" runat="server" Text="Select"  OnClientClick="ch1();" />
Chester Thomas replied to dipa ahuja on 29-Oct-11 02:28 PM
Thanks dipa. I am a novice. Would this be correct as below? I would like to click from the dropdown and have the page open and not necessarily have a button. Thanks for your help
<SharePoint:DVDropDownList AutoPostback="true" runat="server" id="drop" selectedvalue="Select..." OnClientClick="ch1();"
dipa ahuja replied to Chester Thomas on 29-Oct-11 02:34 PM
No dropdownlist doesn't have onClientClick event you have to write it in onChange event:

<SharePoint:DVDropDownList AutoPostback="true" runat="server" id="drop" 
selectedvalue="Select..." onchange="ch1();">