I have a requirement where when an option is selected in the picklist, one of the checkbox should be checked(whose id is PK1 in the code below). I tried executing using Javascript but somehow it's not working. Can someone help me? Here is the code:
<apex:outputLabel value="System"/>
<apex:outputPanel >
<apex:selectList id="sys" value="{!sys}" size="1" onselect="checkthis()">
<apex:selectOption itemvalue="None" itemLabel="--None--"/>
<apex:selectOption itemvalue="1" itemLabel="1" />
<apex:selectOption itemvalue="2" itemLabel="2"/>
<apex:selectOption itemvalue="3" itemLabel="3"/>
<apex:selectOption itemvalue="4" itemLabel="4"/>
<apex:actionSupport event="onchange" reRender="thePageBlock" status="status"/>
</apex:selectList>
<apex:actionStatus startText="Showing Options" id="status" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSection title="Fe" columns="2" id="pb8"
rendered="{!syslicense != '--None--'}">
<apex:inputField value="{!Internal__c.Bat__c}"/>
<apex:inputField value="{!Internal__c.Imp__c}" rendered="{!IF(syslicense =='2',false,true)}"/>
<apex:inputField value="{!Internal__c.Bat1__c}" id="Batvis"/>
<apex:inputField value="{!Internal__c.Mot__c}" id="PK1"/>
</apex:pageBlockSection>
<script type="text/javascript">
function checkthis() {
if (document.getElementById('{!$Component.page.form.thePageBlock.pb7.syslic}') == "2") {
document.getElementById('{!$Component.page.form.thePageBlock.pb8.PK1}').checked = true;
};
}
</script>