Clear form fields when unchecking check

Asked

Viewed 186 times

1

I have a form with a check that the marked shows a div with an input with the name of BancoFinanc, the user can fill in this input normally, but would like when unchecking the input, if filled in by the user, to be cleaned.

What I have and what I’ve tried to do is this, but to no avail:

$(function () {
    $("#chkFinanciamento").click(function () {
        if ($(this).is(":checked")) {
            $("#dvFinanciamento").show();
        } else {
            $("#dvFinanciamento").hide();
            // LIMPA VARIÁVEL
            $("#dvFinanciamento > :BancoFinanc").val();         
        }
    });
});

And also this:

$(function () {
    $("#chkFinanciamento").click(function () {
        if ($(this).is(":checked")) {
            $("#dvFinanciamento").show();
        } else {
            $("#dvFinanciamento").hide();
            // LIMPA VARIÁVEL
            $("#BancoFinanc").attr("value","");     
        }
    });
});

1 answer

1


To clean up the input, just replace:

$("#BancoFinanc").attr("value","");   

for:

$("#BancoFinanc").val("");  
  • Thanks @Allan Andrade, solved my problem.

Browser other questions tagged

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