2013-04-08 125 views
3

請幫我解決我遇到的問題DropDownList。我使用JavaScript「onchange」方法來獲取DropDownList的選定值。我可以獲得價值,但OnSelectedIndexChanged事件不會觸發。希望有人能幫助我。用於獲取選定值我的JavaScript函數是:在JavaScript中使用OnChange方法未觸發SelectedIndexChanged事件

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

的問題是,"ddlcountry_SelectedIndexChanged"方法不叫。

在代碼隱藏我已經加入了Onchange事件如下:

ddlcountry.Attributes.Add("onchange", "showAddress_Byamit(); return false"); 

回答

2

您需要刪除return false

ddlcountry.Attributes.Add("onchange", "showAddress_Byamit();"); 
相關問題