Javascript does not recognize Dropdownlist

Asked

Viewed 31 times

1

With each data change of the dropdownlist I must call a function. But I can’t get him into the job. I used Onchange but it doesn’t work. How to do ?

Code Asp:

<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();
                }
            });

         }

1 answer

0

unfortunately this onchange calls the method in server-side, if you want to do the bind of the event change in the JavaScript, will need to do this in the Code-Behind or directly on JavaScript.

Code-Behind

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

Javascript

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.