checkbox to check whether it shows field or not

Asked

Viewed 97 times

0

I’m working on a registration form with the birth certificate number on it. As you may already know, there is the old format of certificates, with the notary’s name, term, book and sheet (4 fields), and a new format of single field, with 32 digits, 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 appear the four fields to fill with the data of the old certificates. I thought about putting Hidden in the field, and through an if, change to text when checked. Even for this simple idea, I can’t find the syntax. Someone has a solution to this problem?

1 answer

0

I think I’d like it to stay this way:

$(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>
<input type="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">

  • There is an error in this function, and I can not locate. Shows right on the first line.

Browser other questions tagged

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