Display or Hide Fields for Individuals or Companies

0

I have a form that registers Customers, and has the option of being an Individual or Legal Entity, each of which has a few different fields.

I thought about using an @Html.RadioButton with the option Individual and Corporate. When you click on one of the options, the respective fields will appear.

How do I do this?

    
asked by anonymous 07.09.2015 / 23:22

1 answer

7

For this you can use jquery , using classes, like this:

$( document ).ready(function() {
     $(".campoPessoaJuridica, .campoPessoaFisica").hide();
});

$("input:radio[name=tipo]").on("change", function () {   
    if($(this).val() == "pessoaFisica")
    {
    	$(".campoPessoaFisica").show(); 
        $(".campoPessoaJuridica").hide();
    }
    else if($(this).val() == "pessoaJuridica")
    {
    	$(".campoPessoaFisica").hide(); 
        $(".campoPessoaJuridica").show();   
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><inputtype="radio" name="tipo" value="pessoaFisica">Pessoa Física</input>
    <input type="radio" name="tipo" value="pessoaJuridica">Pessoa Jurídica</input>
    <p  class="campoPessoaFisica"><strong>Nome: </strong>
        <input type="text" id="nome">
    </p>
    <p  class="campoPessoaJuridica"><strong>Razão Social: </strong>
        <input type="text" id="razaoSocial">
    </p>
</div>

Fiddle = link

    
08.09.2015 / 14:23