Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I want to call some javascript code from my aspx page on the selected index changed event of drop down list

XML
<asp:dropdownlist id="DropDownList1" runat="server" width="163px" onselectedindexchanged="how to call javascript from here">
</asp:dropdownlist>



Regards,
Prashant
Posted
Updated 11-Aug-10 19:42pm
v2
Comments
Ankur\m/ 12-Aug-10 1:42am    
Edited for formatting.

Or, how about a little JQuery? :)

$(document).ready(function() {
        $("#<%=DropDownList1.ClientID%>").change(function() {
            //Your code goes here
        });
    });
 
Share this answer
 
you can use onchange attribute for doing this.
Use this in the code behind if not a post back,

DropDownList1.Attributes.Add("onchange","Method();");


or alternatively you can directly give this attribute inline.
 
Share this answer
 
You can write:
XML
<asp:DropDownList ID="DropDownList1" runat="server" Width="163px" onchange="javascript:functionName();"/>
 
Share this answer
 
Create Function in Javascript like

JavaScript
function onSelectedindexOccured()
{
 // To Do
}


and from your Aspx page on selectedindexchange event write

<br />
"javascript:onSelectedindexOccured"<br />





thanks
Hiren Solanki
 
Share this answer
 
Comments
Ankur\m/ 27-Aug-10 8:00am    
Reason for my vote of 1
Absolutely rubbish. Do you understand that Javascript is a client side technology. The event you are talking about needs postback. And why on earth would you go back about 15 days and answer a question which is already answered with nothing substantial to add??
Hiren solanki 27-Aug-10 8:07am    
just knowledge sharing
Thanks Ankur /m/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900