function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tyler HarrisTyler Harris 

Use JavaScript to hide field?

I want to hide the Employee field if Scope = "individual sales". Can't get the javascript to fire. I have a onchange attribute on the Scope field calling the hideEmployee() function. I want to hide

JS
function hideEmployee(){
        var employee1 = document.getElementById('{!$Component.frm:comMainCommissions:comFirst:employee:employeeField}');
        var scopez = document.getElementById('{!$Component.frm:comMainCommissions:comFirst:scopes:scopesField}');
            if(scopez == 'Individual Sales'){
             
                employee1.style.display = 'none';
            
            }
            else{
       
            employee1.style.display = 'inline';
            }
        reRenderEmployee();
        }

Visualforce
<apex:actionFunction name="reRenderEmployee" reRender="employee" />
        <apex:sectionHeader rendered="{!isCaseEdit}" title="Case Edit" subtitle="{!objCase.CaseNumber}"/>
        <apex:sectionHeader rendered="{!isCaseNew}" title="New Case" subtitle="{!objCase.CaseNumber}"/>
        
        <!-- Commissions -->
        <apex:pageBlock id="comMainCommissions" title="Case Edit" rendered="{!IsCommissionsRecType}" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!saveCase}"/>
                 <apex:commandButton value="Save & Close" action="{!saveAndCloseCase}"/>
                <apex:commandButton value="Cancel" immediate="true" action="{!cancelCase}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="comFirst" title="Case Information" >
                                   
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Case Owner"></apex:outputLabel>
                    <apex:outputField value="{!objCase.ownerid}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                
                    <apex:outputLabel value="Status"/>
                    <apex:inputField required="true" value="{!objCase.status}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Reason Re-opened" />
                    <apex:inputField required="true" value="{!objCase.Reason_Re_opened__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Number" />
                    <apex:inputField value="{!objCase.CaseNumber}"/>
                </apex:pageBlockSectionItem>
      
				<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Record Type"/>
                    <apex:outputField value="{!objCase.RecordTypeId}"/>
                </apex:pageBlockSectionItem>
				<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Request Type" />
                    <apex:inputField required="true" value="{!objCase.Request_Type__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Priority.inlineHelpText}" rendered="{!!ispivCLASS}">                   
                    <apex:outputLabel value="Priority" />
                    <apex:inputField value="{!objCase.Priority}"/>
                </apex:pageBlockSectionItem>
                

            	
   				
                <apex:pageBlockSectionItem id="scopes" HelpText="{!$ObjectType.Case.fields.Scope__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Scope" />
                    <apex:inputField required="true" value="{!objCase.Scope__c}" id="scopesField" onchange="hideEmployee()"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Origin" />
                    <apex:inputField required="true" value="{!objCase.Origin}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="employee" HelpText="{!$ObjectType.Case.fields.Employee__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Employee" />
                    <apex:inputField required="true"  id="employeeField" value="{!objCase.Employee__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Invoice_Number__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Invoice Number" />
                    <apex:inputField required="false" value="{!objCase.Invoice_Number__c}"/>
                </apex:pageBlockSectionItem>
       			<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Organization" />
                    <apex:inputField required="true" value="{!objCase.Organization__c}"/>
                </apex:pageBlockSectionItem>

                
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Period" />
                    <apex:inputField required="true" value="{!objCase.Period__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Region" />
                    <apex:inputField required="true" value="{!objCase.Region__c}"/>
                </apex:pageBlockSectionItem>
        
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Year" />
                    <apex:inputField required="true" value="{!objCase.Year__c}"/>
                </apex:pageBlockSectionItem>
                
           
            </apex:pageBlockSection>
           
            
         
           
            <apex:pageBlockSection title="Description Information" id="Desc">
                <apex:pageBlockSectionItem id="DescriptionSection">                   
                    <apex:outputLabel value="Subject"/>                    
                    <apex:inputField id="subject" required="{!isCustService}" style="width:500px;" value="{!objCase.Subject}"/>
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Description"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCase.Description}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Internal Comments"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCaseComment.CommentBody}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
           
       
            
            <apex:pageBlockSection title="Web Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Email"/>                    
                    <apex:inputField value="{!objCase.SuppliedEmail}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Company"/>                    
                    <apex:inputField value="{!objCase.SuppliedCompany}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Name"/>                    
                    <apex:inputField value="{!objCase.SuppliedName}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Phone"/>                    
                    <apex:inputField value="{!objCase.SuppliedPhone}"/>
                </apex:pageBlockSectionItem>            
            </apex:pageBlockSection>
            <apex:pageBlockSection title="System Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Source System"/>
                    <apex:outputPanel >
                        <apex:outputfield rendered="{!!($Profile.Name=='System Administrator')}" value="{!objCase.Source_System__c}"/>                  
                        <apex:inputField rendered="{!$Profile.Name=='System Administrator'}" value="{!objCase.Source_System__c}"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Source System ID"/>
                    <apex:outputPanel >    
                        <apex:outputfield rendered="{!!($Profile.Name=='System Administrator')}" value="{!objCase.Source_System_ID__c}"/>                               
                        <apex:inputField rendered="{!$Profile.Name=='System Administrator'}" value="{!objCase.Source_System_ID__c}"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Checked for Spam"/>                    
                    <apex:inputField value="{!objCase.Checked_for_Spam__c}"/>
                </apex:pageBlockSectionItem>            
            </apex:pageBlockSection>
        </apex:pageBlock>

 
pconpcon
If you print the value of your scopez variable out, do you get the expected property?  Have you thought about using the built in rendered attribute in conjunction with the reRender attribute to do this completely inside of Visualforce?