Click to See Complete Forum and Search --> : fire a javascript function with drop down list


bjswift
May 24th, 2005, 08:36 AM
I am using an ASP.net drop down list box, and need to call a client side function when its index changes. In the HTML, inside the <asp:dropDownList... area, I try to refrerence the onSelectedIndexChanged event, but get a Compilation Error when trying to run the application.

Is it the fact that I am using a .net control? I have tried, just for kicks, the onClick call, and displayed an alert inside the function it is fireing, which works, but of course doesn't allow any change in the DDL box, because the alert interupts any user interaction with the DDL..... So, I'm not sure what to do. Thanks!!

sarvesh189
May 31st, 2005, 05:30 AM
.aspx page

<asp:DropDownList id="ddlkeys" Runat="server">
<asp:ListItem Value="0" Selected="True">Select...</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList >

now write on

page_load()
{
id.attributes.add("onSelectedindexchange","return fun_call();")

}

in .aspx page

<body>
<script language=javascript>
function fun_call()
{
---javascript code
}
</script>

sarvesh