Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdown like tihs

<asp:DropDownList ID="cmbexch" runat="server">


And trying to call javascript like this.
On page load i am writting this line
cmbexch.Attributes.Add("OnSelectedIndexChanged", "javascript:fillmkttype()")


but it is not working
Posted

Use attribute onchange inside asp:dropdown

XML
<asp:DropDownList ID="ddShed" Width="120px" onchange="GetBalanceQty(this.options[this.selectedIndex].value);"
                                    runat="server">
                                </asp:DropDownList>

JavaScript Function----

C#
function GetBalanceQty(val)
    {
//in val u get dropdown list selected value
        var id = val;
}


Thanks & Regards,
satya.
please mark as answer if helpful.
 
Share this answer
 
SQL
cmbexch.Attributes.Add("onChange", "return OnSelectedIndexChange();")

<code> OnSelectedIndexChange()</code> should be your  Javascript function that will be call <code>DropDownList </code> Seleted index is changes.

Something Like
function OnSelectedIndexChange()
{
alert('index changed')
}


You can also pass the object to get the value of selected item as well.
 
Share this answer
 
Comments
mayur csharp G 29-Aug-11 7:01am    
Hi all
i solved like this
i wrote simply
cmbexch.Attributes.Add("onchange", "javascript:fillmkttype();")

on page load
Hello Dear,

You can call the java script function in the design page itself by adding

onselectedIndexChanged="function();"

Hope it will help you to call the javascript function on selected index changed event.
 
Share this answer
 
u can call in this way also
in dropdown selected index changed event

page.ClientScript.RegisterStartupScript(this.GetType(),"a","<script language='javascript'>fillmkttype();</script>");
 
Share this answer
 
v2
Comments
Abhijit Jana 29-Aug-11 6:59am    
How this will work on Selection Index change ?
hitech_s 29-Aug-11 7:02am    
write this line in selectedindexchanged event
it will fire the javascript function
<pre lang="c#"><pre lang="CSS"><a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>&<big><small></small></big></pre></pre>
 
Share this answer
 

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