I have written one JavaScript function as follows:
function CalcTotalAmt()
{
----------
-----------
}
I have one DropDownList,
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>
I need to call the above JavaScript function in the DropDownList's SelectedIndexChanged Event. I tried like below;
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
ddl.Attributes.Add("onchange", "return CalcTotalAmt();");
}
But the JavaScript function is not executing. How to call the JavaScript function in DropDownList Change Event?
First the ASP.Net DropDownList will be referenced using JavaScript or jQuery on Client Side and then its SelectedIndexChanged event will be called by making use of the __doPostBack JavaScript function.
Add("onChange", "return OnSelectedIndexChange();") <code> OnSelectedIndexChange()</code> should be your Javascript function that will be call <code>DropDownList </code> Seleted index is changes. You can also pass the object to get the value of selected item as well.
The DropDownList control is a web server element that creates the drop-down menu and lets users select a single item from various options. You can add any number of items to the DropDownList. Almost all web pages contain a drop-down list, but it is mostly present in registration forms or sign-in pages.
Or you can do it like as well:
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" onchange="javascript:CalcTotalAmt();" OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With