views:

24

answers:

3

I want to access drop down menu's variable in java script on change event, here is my code

 <asp:DropDownList ID="DropDownList1" runat="server" onchange="document.location.href = url_Lookbook;" >
        <asp:ListItem Value="0">hello</asp:ListItem>
        <asp:ListItem Value="1">world</asp:ListItem>
        </asp:DropDownList>

here is the script coding:

<script type="text/javascript">
    var url_Lookbook = "http://microsoft.com";
</script>

My question is how do I pass down value=0 or value = 1 to different page, any help is appreciated.

A: 

This is how I do it, completely in server side code. You don't have to use javascript (if you aren't required to)

                    <asp:DropDownList ID="ddlGlobalDestinations" runat="server" OnSelectedIndexChanged="ddlGlobalDestinations_SelectedIndexChanged" AutoPostBack="true">
                        <asp:ListItem Text="StackOverflow" Value="http://www.stackoverflow.com"&gt;&lt;/asp:ListItem&gt;
                        <asp:ListItem Text="Google" Value="http://www.google.com/"&gt;&lt;/asp:ListItem&gt;
                    <asp:ListItem Text="Microsoft" Value="http://www.microsoft.com/"&gt;&lt;/asp:ListItem&gt;                    
                    </asp:DropDownList>

here is the c# code-behind

protected void ddlGlobalDestinations_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Redirect(ddlGlobalDestinations.SelectedValue, true);
}
TheGeekYouNeed
A: 

onchange="document.location.href = url_Lookbook + '?param=' + this.value;" appears to work in FF3 and IE7.

joelt
A: 

If you wrote it as a javascript function, it would be simpler

 <asp:DropDownList ID="DropDownList1" runat="server" onchange="navFromList(this.value);" >
        <asp:ListItem Value="0">hello</asp:ListItem>
        <asp:ListItem Value="1">world</asp:ListItem>
</asp:DropDownList>

<script type="text/javascript">
    function navFromList( qsParam )
    {
        document.location.href = "http://microsoft.com?arg=" + qsParam;
        return false;
    }
</script>
Thomas
worked like a charm. Thanks
fzshah76