Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me i'm facing a problem with dropdown list
i'm using javascript method "onchange" to get dropdown selected value i get the value but dropdown selectedIndexChanged event not firing
please someone help me

my javascript function is that for getting selected value:
JavaScript
 <script type="text/javascript" language="javascript">
        function showAddress_Byamit()
         {
             var e = document.getElementById("TabC_tp1_ddlcountry");
             var country = e.options[e.selectedIndex].text;
          }
</Script>

ASP.NET
<asp:DropDownList
                ID="ddlcountry" runat="server" AutoPostBack="True" Height="20px" EnableViewState="true"
                OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged" TabIndex="4"  onchange="showAddress_Byamit(); return false"
                Width="100px" >

here problem is that event "ddlcountry_SelectedIndexChanged" not firing
Posted
Updated 7-Apr-13 20:20pm
v2
Comments
virang_21 8-Apr-13 2:07am    
Set AutoPostBack property to true for dropdown
amitavin_Sharma 8-Apr-13 2:11am    
sir i already set property as autopostback="true"
amitavin_Sharma 8-Apr-13 2:16am    
my javascript function is that for getting selected value:
<script type="text/javascript" language="javascript">
function showAddress_Byamit()
{
var e = document.getElementById("TabC_tp1_ddlcountry");
var country = e.options[e.selectedIndex].text;
}
</Script>
it works well


<asp:DropDownList
ID="ddlcountry" runat="server" AutoPostBack="True" Height="20px" EnableViewState="true"
OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged" TabIndex="4" onchange="showAddress_Byamit(); return false"
Width="100px" >

here problem is that event "ddlcountry_SelectedIndexChanged" not firing
virang_21 8-Apr-13 2:23am    
Add this to your javascript function at the end

__doPostBack("<%=ddlCountry.ClientID %>", '');
amitavin_Sharma 8-Apr-13 2:48am    
sir this is not working the error is ;
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

one solution can be, in your JavaScript function you can postback the page,
set the onChange() event on your DropDownList only...then in your JavaScript, manually force the postback using something like the

JavaScript
__doPostBack('<%= YourDropdownList.ClientID %>', '');


Hope It will help you.

Good luck.
 
Share this answer
 
Comments
amitavin_Sharma 8-Apr-13 2:58am    
sir this is not working as i want to do
amitavin_Sharma 8-Apr-13 4:48am    
when i'm using like this
__doPostBack(country.id, '');
then selectedIndexChanged is fired but javascript functionality is conflicted
You are writing return false while calling javascript code. If you remove that it should work. Try and post if still not working.

HTML
onchange="showAddress_Byamit(); return false"
 
Share this answer
 
v2
<script type="text/javascript">

function showAddress_Byamit() {
var e = $('#<%= ddlcountry.ClientID %>').val();
var country = e;
}
</script>
<asp:dropdownlist id="ddlcountry" runat="server" autopostback="True" height="20px"
EnableViewState="true" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged"
TabIndex="4" onchange="javascript:showAddress_Byamit();" Width="100px">
<asp:listitem text="Australia" value="1">
<asp:listitem text="Japan" value="2">
</asp:dropdownlist>
 
Share this answer
 
v3
Comments
amitavin_Sharma 8-Apr-13 3:16am    
sir here i'm filling another dropdownlist on changing index of first dropdown in other word i'm using databound with this dropdown list
PRAKASH9 8-Apr-13 3:19am    
so what?

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