OnClick Event in A Select Dropdown Menu (ASP)

Posted on 2010-01-08
Last Modified: 2013-11-25
Is it possible to have an onClick event fired off when something is selected from a Select dropdown list in ASP?  Similar to how a button when clicked performs an action I would like when an item is selected from a dropdown list that it immediately opens a new page.  This way it does not require the user to select the item from the drop down, then hit a submit button.

this is what I used for one of my buttons.
<input type="button" value="Refresh" onClick="location.href='<%= Me.NewURL.ToString() %>';">

Is there a way to use this method for a dropdown?  Something like
<input type="dropdown" value="Refresh" onClick="location.href='<%= Me.NewURL.ToString() %>';">
Question by:rkneal
    LVL 18

    Expert Comment


    You can simply do something like:

    <asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_OnSelectedIndexChanged">
        <asp:ListItem .../>

    And in code behind:

    Protected Sub ddl_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddl.SelectedIndexChanged
    End Sub

    LVL 2

    Accepted Solution


    I think this is what you need if you're using classic ASP.  You can change _top to _blank if you want a new browser window.

    <form action="../">
    <select onchange="[this.selectedIndex].value,'_top')">
        <option value="">Choose a destination...</option>
        <option value="">YAHOO</option>
        <option value="">GOOGLE</option>
        <option value="">ALTAVISTA</option>
        <option value="">AMAZON</option>
        <option value="">ARTLUNG</option>


    Author Comment

    Shank - What you have does work but I get a prompt when I click an item from the drop down.  The prompt says

    "Javascript: A script has requested that a new URL be loaded.  Do you wish to load http://XXX.XX"

    This happens on a blackberry browser.  If I click Yes, it opens the page but if I can get fix this prompt then that would be all I need.  Any ideas?

    Author Closing Comment

    Works to accomplish what I want but I have to find out a way around an annoying prompt.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now