5
What I wish to do
The guy has in the form the option of registering natural or legal person. I want that when he clicks on the radio of the individual, he cleans the legal person input, and vice versa.
What I did
I feel like a fool. I made this code and then looked on the Internet to verify if there was something wrong. To take the test, I typed in the CNPJ, and then clicked in person, and filled out the CPF. After that I returned to legal person, and the CNPJ was still inside, so I clicked again in person, and the CPF had disappeared, remaining only the CPF placeholder, but when I clicked to fill the value appeared.
My Code
HTML form
<section class="col col-md-3">
<label for="id_receiver-destiny_type_people_0">
<input id="id_receiver-destiny_type_people_0" type="radio" value="juridic" checked name="receiver-destiny_type_people">
Pessoa Jurídica
</label>
</section>
<section class="col col-md-3">
<label for="id_receiver-destiny_type_people_1">
<input id="id_receiver-destiny_type_people_1" type="radio" value="individual" name="receiver-destiny_type_people">
Pessoa Física
</label>
</section>
<input id="id_receiver-cnpj" name="receiver-cnpj" placeholder="CNPJ" type="text" />
<input id="id_receiver-cpf" name="receiver-cpf" placeholder="CPF" type="text" />
jQuery
$("input[name='receiver-destiny_type_people']").bind('click', $.proxy(this.checkCompanyType, this));
checkCompanyType: function(){
companyType = $("input[name='receiver-destiny_type_people']").val();
if(companyType == "juridic") {
$("#id_receiver-cpf").val("");
} else if (companyType == "individual") {
$("#id_receiver-cnpj").val("");
}
},
Quotation marks missing: $("#id_receiver-cnpj"). val(). Correct would be $("#id_receiver-cnpj"). val('');
– Emir Marques
Sorry @Emirmarques, I have this in the code, I accidentally took it. I updated the question.
– Allan Ramos
I posted the resolution in the first reply
– Emir Marques