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
zmzigazmziga 

Get value from InputField

I have an input field.

<apex:inputField label="Label:" value="{!User__c.attribute__c}"/>

 

And based on the written input, I'd like to have another field shown/hidden. (I rerender second inputfield after changing first inputfield)


 <apex:inputField label="Label 2:" value="{!User__c.attribute2__c}" rendered="{!IF(User__c.attribute__c='something',true,false)}"/>

 

But I assume, that I cannot get value from first field like that.

 

My question is how to get value from inputfield, so I can use later it in "rendered"?

Best Answer chosen by Admin (Salesforce Developers) 
KodiKodi

Hi,

 

<apex:inputField label="Label:" value="{User__c.attribute__c}">

<apex:actionSupport event="onchange" />

</apex:inputField>

 

<apex:outputPanel id="ot" rendered="{User__c.attribute__c!=null}">

<apex:inputField label="Label 2:" value="{!User__c.attribute2__c}"/>

</apex:outputPanel>

 

try this if first inputfield have value means shown on second inputfiled or otherwise hidden.

 

if u want to get the value from inputfield means using controller or javascript.

All Answers

Taiki YoshikawaTaiki Yoshikawa

Hi.

 

How about this?

 

Page

<apex:page standardController="Account" id="page">
    <apex:form id="form">
        <apex:actionFunction name="refresh" reRender="blockSection" />
        <apex:pageBlock id="block">
            <apex:pageBlockSection id="blockSection">
                <apex:inputField value="{!Account.Name}" onchange="return changeField();" />
                <apex:outputText value="OK" rendered="{!IF(Account.Name != NULL, true, false)}" id="output" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script>
        function changeField() {
            refresh();
            return false;
        }
    </script>
</apex:page>

 

Regards,

souvik9086souvik9086

<apex:inputField label="Label:" value="{!User__c.attribute__c}">

<apex:actionsupport event="onchange" rerender="details"/>

</apex:inputField>

 

<apex:outputpanel id="details">

<apex:inputField label="Label 2:" value="{!User__c.attribute2__c}" rendered="{!IF(User__c.attribute__c='something',true,false)}"/>

</apex:outputpanel>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

zmzigazmziga

Unfortunately this solution does not work. It is as if this does not work:

rendered="{!IF(User__c.attribute__c='something',true,false)}"

 

 

Because if I output result for User__c.attribute__c ..it is always empty. Even if I set default value for User__c.attribute__c, it still shows as empty. That's why I asked how to get value from InputField, because this does not work.

 


edit: Does that change anything if first inputfield is picklist? So when I select value from picklist, it shows another field or it hides it.

KodiKodi

Hi,

 

<apex:inputField label="Label:" value="{User__c.attribute__c}">

<apex:actionSupport event="onchange" />

</apex:inputField>

 

<apex:outputPanel id="ot" rendered="{User__c.attribute__c!=null}">

<apex:inputField label="Label 2:" value="{!User__c.attribute2__c}"/>

</apex:outputPanel>

 

try this if first inputfield have value means shown on second inputfiled or otherwise hidden.

 

if u want to get the value from inputfield means using controller or javascript.

This was selected as the best answer
souvik9086souvik9086

Check like this

 

<apex:inputField label="Label:" value="{!User__c.attribute__c}">

<apex:actionsupport event="onchange" rerender="details"/>

</apex:inputField>

 

<apex:outputpanel id="details">

<apex:inputField label="Label 2:" value="{!User__c.attribute2__c}" rendered="{!User__c.attribute__c == 'something'}"/>

</apex:outputpanel>

zmzigazmziga

Thank you, Kodi!

 

This one worked. I don't know yet why, but if I used "reRender" it didn't work. But without "rerender" it worked. Sadly it refreshes whole page and not just section. If anyone knows why this does not work, please let me know.

 

Thank you for all your answers!

Taiki YoshikawaTaiki Yoshikawa

This did not work...

<apex:page standardController="Account" id="page">
    <apex:form id="form">
        <apex:pageBlock id="block">
            <apex:pageBlockSection id="blockSection">
                <apex:inputField value="{!Account.Type}">
                    <apex:actionSupport event="onchange" reRender="output" />
                </apex:inputField>
                <apex:outputText value="OK" rendered="{!Account.Type != NULL}" id="output" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 I worked at this.

<apex:page standardController="Account" id="page">
    <apex:form id="form">
        <apex:pageBlock id="block">
            <apex:pageBlockSection id="blockSection">
                <apex:inputField value="{!Account.Type}">
                    <apex:actionSupport event="onchange" reRender="blockSection" />
                </apex:inputField>
                <apex:outputText value="OK" rendered="{!Account.Type != NULL}" id="output" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>