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 diff开发者_运维问答erent page, any help is appreciated.
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>
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"></asp:ListItem>
<asp:ListItem Text="Google" Value="http://www.google.com/"></asp:ListItem>
<asp:ListItem Text="Microsoft" Value="http://www.microsoft.com/"></asp:ListItem>
</asp:DropDownList>
here is the c# code-behind
protected void ddlGlobalDestinations_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect(ddlGlobalDestinations.SelectedValue, true);
}
onchange="document.location.href = url_Lookbook + '?param=' + this.value;" appears to work in FF3 and IE7.
精彩评论