Clear form fields by clearing check

1

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

What I have and what I tried to do was this, but without success:

$(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","");     
        }
    });
});
    
asked by anonymous 17.08.2016 / 16:11

1 answer

1

To clean input , simply replace:

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

by:

$("#BancoFinanc").val("");  
    
17.08.2016 / 16:18