• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3313
  • Last Modified:

OnClick Event in A Select Dropdown Menu (ASP)

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() %>';">
0
rkneal
Asked:
rkneal
  • 2
1 Solution
 
carlnorrbomCommented:
Hi,

You can simply do something like:

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

And in code behind:

Protected Sub ddl_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddl.SelectedIndexChanged
    Response.Redirect(Me.NewURL.ToString())
End Sub

/Carl.
0
 
shankwheatCommented:
Hi

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="window.open(this.options[this.selectedIndex].value,'_top')">
    <option value="">Choose a destination...</option>
    <option value="http://www.yahoo.com/">YAHOO</option>
    <option value="http://www.google.com/">GOOGLE</option>
    <option value="http://www.altavista.com/">ALTAVISTA</option>
    <option value="http://www.amazon.com/">AMAZON</option>
    <option value="http://artlung.com/">ARTLUNG</option>
</select>
</form>

Shank
0
 
rknealAuthor Commented:
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?
0
 
rknealAuthor Commented:
Works to accomplish what I want but I have to find out a way around an annoying prompt.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now