checkbox to determine if it shows field or not

0

I am working on a registration form where the birth certificate number appears. As you may know, there is the old format of certificates, with the name of the notary, term, book and sheet (4 fields), and a new 32-digit single-field format where all this information is implicit. I put in my form only a text field to put these 32 digits of the new certificate, and only a checkbox called old certificate, which when clicked (checked) will make the four fields appear to fill in the data of the old certificates. I thought of putting hidden in the field, and through an if, switch to text when checked. Even for this simple idea, I can not find the syntax. Does anyone have a solution to this problem?

    
asked by anonymous 16.06.2018 / 21:29

1 answer

0

I think I'd like it to look like this:

$(document).ready(function(){
  $("#potato").on("click", function(event) {
    var check = $("#potato").prop("checked");
    if(check){
        //exibe campos
        $("#idOne").prop("type", "text");
        $("#idTwo").prop("type", "text");
    }
    else{
        //oculta e zera campos
        $("#idOne").prop("type", "hidden").val("");
        $("#idTwo").prop("type", "hidden").val("");
    } 
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="checkbox" id="potato" name="potato" value="potato"><label for="potato">Potato</label><br>
<input type="hidden" value="one" id="idOne">
<input type="hidden" value="two" id="idTwo">
    
17.06.2018 / 04:55