Skip to main content
added 104 characters in body
Source Link

I have a small problem with a validation here

  <script>
    function myFunction(V) {
        var inputcpf = document.getElementById("CPF");
        var inputcnpj = document.getElementById("CNPJ");
        
        if(V.Value =='CPF'){
            inputcpf.style.display='block';
            inputcpf.required=True;
            inputcnpj.style.display='none';
            inputcnpj.removeattribute("required");
        }else{
            inputcnpj.style.display='block';
            inputcnpj.required=True;
            inputcpf.style.display='none';
            inputcpf.removeattribute("required");                
            
        }
        
    }    
    
    </script>

<apex:selectRadio styleClass="radioinput" onChange="myFunction(this);">
                        <apex:selectOption itemlabel="CPF" itemValue="CPF" />   
                        <apex:selectOption itemlabel="CNPJ" itemValue="CNPJ"/> 
                    </apex:selectRadio>     
                                          
                <td><apex:inputField style="display:none" id="CPF" value="{!Cliente__c.CPF__c}"/></td>                    
                <td><apex:inputField style="display:none" id="CNPJ" value="{!Cliente__c.CNPJ__c}"/></td>   

do notI want to, when I click on cpf, hide fieldscnpj and remove the true request, and the reverse as well. But the function is not working :(

I have a small problem with a validation here

  <script>
    function myFunction(V) {
        var inputcpf = document.getElementById("CPF");
        var inputcnpj = document.getElementById("CNPJ");
        
        if(V.Value =='CPF'){
            inputcpf.style.display='block';
            inputcpf.required=True;
            inputcnpj.style.display='none';
            inputcnpj.removeattribute("required");
        }else{
            inputcnpj.style.display='block';
            inputcnpj.required=True;
            inputcpf.style.display='none';
            inputcpf.removeattribute("required");                
            
        }
        
    }    
    
    </script>

<apex:selectRadio styleClass="radioinput" onChange="myFunction(this);">
                        <apex:selectOption itemlabel="CPF" itemValue="CPF" />   
                        <apex:selectOption itemlabel="CNPJ" itemValue="CNPJ"/> 
                    </apex:selectRadio>     
                                          
                <td><apex:inputField style="display:none" id="CPF" value="{!Cliente__c.CPF__c}"/></td>                    
                <td><apex:inputField style="display:none" id="CNPJ" value="{!Cliente__c.CNPJ__c}"/></td>   

do not want to hide fields :(

I have a small problem with a validation here

  <script>
    function myFunction(V) {
        var inputcpf = document.getElementById("CPF");
        var inputcnpj = document.getElementById("CNPJ");
        
        if(V.Value =='CPF'){
            inputcpf.style.display='block';
            inputcpf.required=True;
            inputcnpj.style.display='none';
            inputcnpj.removeattribute("required");
        }else{
            inputcnpj.style.display='block';
            inputcnpj.required=True;
            inputcpf.style.display='none';
            inputcpf.removeattribute("required");                
            
        }
        
    }    
    
    </script>

<apex:selectRadio styleClass="radioinput" onChange="myFunction(this);">
                        <apex:selectOption itemlabel="CPF" itemValue="CPF" />   
                        <apex:selectOption itemlabel="CNPJ" itemValue="CNPJ"/> 
                    </apex:selectRadio>     
                                          
                <td><apex:inputField style="display:none" id="CPF" value="{!Cliente__c.CPF__c}"/></td>                    
                <td><apex:inputField style="display:none" id="CNPJ" value="{!Cliente__c.CNPJ__c}"/></td>   

I want, when I click on cpf, hide cnpj and remove the true request, and the reverse as well. But the function is not working :(

Source Link

Hide and Show inputField Based upon Radio Button

I have a small problem with a validation here

  <script>
    function myFunction(V) {
        var inputcpf = document.getElementById("CPF");
        var inputcnpj = document.getElementById("CNPJ");
        
        if(V.Value =='CPF'){
            inputcpf.style.display='block';
            inputcpf.required=True;
            inputcnpj.style.display='none';
            inputcnpj.removeattribute("required");
        }else{
            inputcnpj.style.display='block';
            inputcnpj.required=True;
            inputcpf.style.display='none';
            inputcpf.removeattribute("required");                
            
        }
        
    }    
    
    </script>

<apex:selectRadio styleClass="radioinput" onChange="myFunction(this);">
                        <apex:selectOption itemlabel="CPF" itemValue="CPF" />   
                        <apex:selectOption itemlabel="CNPJ" itemValue="CNPJ"/> 
                    </apex:selectRadio>     
                                          
                <td><apex:inputField style="display:none" id="CPF" value="{!Cliente__c.CPF__c}"/></td>                    
                <td><apex:inputField style="display:none" id="CNPJ" value="{!Cliente__c.CNPJ__c}"/></td>   

do not want to hide fields :(