I would like a hint on checked, select option how do I clear fields if a person selects an option

0

Good morning I would like a hint about checked, select option how do I clear fields if a person selects an option

<form method="post">
                    <input type="hidden" name="id" value="<!--# Valor=Cliente.Id #-->" />

                    <div class="row">
                        <div class="small-12 columns">
                            <label class="required">Tipo de cliente</label>

                            <input type="radio" id="rjuridica" class="switchVal" data-show="juridica" data-hide="fisica" name="atipo" value="juridica" <!--# Fazer=Cliente.ChecarTipo.Juridica #-->> 
                            <label for="rjuridica">Pessoa jurídica</label>

                            <input type="radio" id="rfisica" class="switchVal" data-show="fisica" data-hide="juridica" name="atipo" value="fisica" <!--# Fazer=Cliente.ChecarTipo.Fisica #-->>
                            <label for="rfisica">Pessoa física</label>
                        </div>
                    </div>

I would like that when a person clicks on legal entity clean the field of the imput cpf with old information as a physical person clears the cnpj of the field

                                <div class="small-3 columns">
                                <label class="required">CPF</label>
                                <input class="cpf" type="text" name="acpf" value="<!--# Valor=Cliente.Cpf #-->"/>
                            </div>



                            <div class="small-3 columns">
                            <label class="required">CNPJ</label>
                            <input class="cnpj" type="text" name="acnpj" value="<!--# Valor=Cliente.CNPJ #-->"/>
                        </div>

by jquerry or php

    
asked by anonymous 19.09.2017 / 16:11

2 answers

1

Use onclick , so when you click, it will delete the contents of the input.

link

$("#rjuridica").click(function(){
    $(".cpf").val(" ");
});

With this function, when you press the radio, it will clear the input.

    
19.09.2017 / 16:32
1

I believe this cleanup involves validation, and just clearing the field will not prevent it from being submitted, ideally something like that ...

$(document).ready(function(){
                        var cpf = '';
                        var cnpj = '';
                        $('input[type="radio"]').change(function(){
                          if($(this).val() == 'juridica'){
                    	if($('.cpf').val() != cpf){cpf = $('.cpf').val();}
                          	$('.cpf').val('');
                          	$('.cpf').attr('disabled', 'true');
                            $('.cnpj').removeAttr('disabled');
                            $('.cnpj').val(cnpj);
                          }else{
                          if($('.cnpj').val() != cnpj){cnpj = $('.cnpj').val();}
                          	$('.cnpj').val('');
                            $('.cnpj').attr('disabled', 'true');
                            $('.cpf').removeAttr('disabled');
                            $('.cpf').val(cpf);
                          }
                        })
                        })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="hidden" name="id" value="<!--# Valor=Cliente.Id #-->" />

                    <div class="row">
                        <div class="small-12 columns">
                            <label class="required">Tipo de cliente</label>

                            <input type="radio" id="rjuridica" class="switchVal" data-show="juridica" data-hide="fisica" name="atipo" value="juridica">
                            <label for="rjuridica">Pessoa jurídica</label>

                            <input type="radio" id="rfisica" class="switchVal" data-show="fisica" data-hide="juridica" name="atipo" value="fisica">
                            <label for="rfisica">Pessoa física</label>
                        </div>
                    </div>
                    
                    <div class="small-3 columns">
                                <label class="required">CPF</label>
                                <input class="cpf" type="text" name="acpf" value=""/>
                            </div>



                            <div class="small-3 columns">
                            <label class="required">CNPJ</label>
                            <input class="cnpj" type="text" name="acnpj" value=""/>
                        </div>
    
19.09.2017 / 16:43