JavaScript does not recognize Dropdownlist

1

At every dropdownlist data change I should call a function. But I can not get it into the function. I used Onchange but it does not work. How to do?

Asp code:

<asp:DropDownList name="ddlFormaPagamento" ID="ddlFormaPagamento" runat="server"
Font-Bold="true" CssClass="newCombo" Width="340" AutoPostBack="True"onchange="javascript:VerificaIndisponibilidade();">
</asp:DropDownList>


//Função:
function VerificaIndisponibilidade() {

            $.ajax({
                type: "POST",
                url: "ReservaTarifario.aspx/VerificaIndisponibilidade",
                data: JSON.stringify({ MsgErro: MsgErro }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: validar(Erro, "Indisponível"),
                failure: function () {
                    alert('');
                    fecharLoad();
                }
            });

         }
    
asked by anonymous 29.07.2016 / 18:01

1 answer

0

Unfortunately this onchange calls the method in server-side , if you want to bind of event change in JavaScript , you need to do this in Code-Behind or direct in JavaScript . >

Code-Behind

ddlFormaPagamento.Attributes["onChange"] = "VerificaIndisponibilidade();";

JavaScript

$("select[id$='ddlFormaPagamento']").on("change", VerificaIndisponibilidade);

Another point, you have set AutoPostBack="True" this will cause the event on the server side to fire whenever you select a value, forcing PostBack complete (if you do not have a UpdatePanel ).

    
29.07.2016 / 18:13