Problem in an input field in a Javascript function

Asked

Viewed 51 times

1

I made this function in Javascript to use in Visual Studio and add 3 fields in a div and the three values are recorded in my table, but the first field I type a value for it but this value is not passed to my table, the other two that are a list this yes is recorded, could help me identify if I did something wrong ? The field with problem is DES_EMAIL_PESSOA, it in my table is formatted as nvarchar(255)

$(function () {
    var qtdEmails = 0;
    $("#btn-add-Emails").click(function (e) {
        e.preventDefault();

        var blocoEmails =
            '<div class="row">' +
            '     <div class="col-md-2">' +
            '        <button class="btn btn-danger" id="btn-remover-Emails">Remover</button>' +
            '     </div>' +
            '       <div class="col-md-3">' +
            '           <input type="text" name="PESSOAS_EMAILS_EMA[' + qtdEmails + ' ].DES_EMAIL_PESSOA" placeholder="Email" class="form-control txt-email">' +
            '       </div>' +
            '           <div class="col-md-3">' +
            '               <select name="PESSOAS_EMAILS_EMA[' + qtdEmails + '].LIS_TIPO_EMAIL" placeholder="Tipo" class="form-control sel-tipo">' +
            '                   <option value="P">PESSOAL</option>' +
            '                   <option value="R">PROFISSIONAL</option>' +
            '                   <option value="O">OUTROS</option>' +
            '               </select>' +
            '           </div>' +
            '               <div class="col-md-2">' +
            '                   <select name="PESSOAS_EMAILS_EMA[' + qtdEmails + '].STS_EMAIL_PESSOA" placeholder="Status" class="form-control sel-sts">' +
            '                       <option value="A">ATIVO</option>' +
            '                       <option value="I">INATIVO</option>' +
            '                   </select>' +
            '               <div />' +
            '</div>';

        $("#div-Emails").append(blocoEmails);

        qtdEmails++;
    });

    $("#div-Emails").on("click", ".btn-remover-Emails", function (e) {
        e.preventDefault();

        $(this).parent().parent().remove();

        qtdEmails--;

        $("#div-Emails .row").each(function (indice, elemento) {
            $(elemento).find(".txt-email").attr("name", "PESSOAS_EMAILS_EMA[" + indice + "].DES_EMAIL_PESSOA");
            $(elemento).find(".sel-tipo").attr("name", "PESSOAS_EMAILS_EMA[" + indice + "].LIS_TIPO_EMAIL");
            $(elemento).find(".sel-sts").attr("name", "PESSOAS_EMAILS_EMA[" + indice + "].STS_EMAIL_PESSOA");
        });
    });
});
No answers

Browser other questions tagged

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