You need to sign in to do that
Don't have an account?

onchange event not working for dependent picklist
Hi All,
I am facing problem with onchange event of <apex:inputfield> that actually calls <apex:actionFunction>
The problem is I have a depenedent picklist. When I choose value in controlling picklist the dependent picklist will enabled and values will be rendered. When there is more than one value in the dependent picklist there is no problem with the onchange event but when there is only one value, as per dependent picklist behaviour, that value was selected by default at that time onchange event is not working.
There is one solution to use javascript and add a dummy value like --select-- in the picklist but is there any other option, hence user do not have to select the dependent picklist value if there is only one value.
I am facing problem with onchange event of <apex:inputfield> that actually calls <apex:actionFunction>
The problem is I have a depenedent picklist. When I choose value in controlling picklist the dependent picklist will enabled and values will be rendered. When there is more than one value in the dependent picklist there is no problem with the onchange event but when there is only one value, as per dependent picklist behaviour, that value was selected by default at that time onchange event is not working.
There is one solution to use javascript and add a dummy value like --select-- in the picklist but is there any other option, hence user do not have to select the dependent picklist value if there is only one value.
You can set the selectedIndex to -1 (in Javascript), so that the value will not be selected by default.
Once you select it manually, your OnChange event will be fired.
Here is the sample syntax. You may want to add this code to the Onchange event of the controller field.
Let me know if this helps.
Actually I have three field A, B, C
And they are dependent like below
If I select A the value comes in field B and if I selected something in B then C will be enable and value will be populated. A and B field is working fine but when there is only one value in field C it does not fire the onchange event abc() of field C.
<apex:inputField value="{!myobj__c.A__c}" required="true" />
<apex:inputField value="{!myobj__c.B__c}" required="true" />
<apex:inputfield value="{!myobj__c.C__c}" required="true" onchange="abc()" />
<apex:actionFunction name="abc" action="{!callCtr}" rerender="block1"/>
As suggested I have write a javascript onchange function on field B but after doing that C field is disable and the value is not populated.
It will be helpful if you let me know the full code of javascript.
And, reset C onchange of B.
Your code will look like this. You can fetch the IDs (used in getElementById in the JS function) of these pick lists using "Inspect Element" option in the browser.
Hope this helps.
Is there any other way to do this.
Was that not working for you?