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
VSK98VSK98 

Passing the value from vfpage to controller using inputtext but getting null

Hi All,

I have build sample vf page passing the values from vf page to controller using inputtext........But i am getting null value 

Here is my code: 
<apex:page controller="Displayoutput">
<script type="text/javascript">
    function DisplayErr(){
    if(document.getElementById('{!$Component.frm.Num}').value == ''){
    alert("Please fill the Number");
    }
    else{
    callDisplay();
    alert("Perfect");
    }
}
</script>
 <apex:form id="frm">
  <apex:actionFunction action="{!Display}" name="callDisplay"/>
  <apex:outputText value="Enter The Number"/>
  <apex:inputText  id="Num" value="{!text}"/>
  <apex:commandButton value="Validate" onclick="DisplayErr()" />
  Sample Output:
  
 </apex:form>
</apex:page>

Controller: 
Public class Displayoutput{
public string dis{get;set;}
public string text{get;set;}

public String gettext(){
        return text;
    }

public Displayoutput(){

system.debug('Enter in Constructor*****');
system.debug('TEXTVALUE*****'+text);
}

public void Display(){
    system.debug('TEXTVALUE*****'+text);
   
}



}

Pls give suggwestions.............

Adv Thnx
VSK98
ManojSankaranManojSankaran
Hi VSK98,

Whenever you are calling an action function you have to reRender any tag. Use the below action funtion. You will get the Name getting displayed in the log.


  <apex:actionFunction action="{!Display}" name="callDisplay" reRender="frm"/>



Thanks
Manoj S
 
swati_sehrawatswati_sehrawat
<apex:page controller="Displayoutput">
<script type="text/javascript">
    function DisplayErr(){
    if(document.getElementById('{!$Component.frm.Num}').value == ''){
    alert("Please fill the Number");
    }
    else{
    alert("Perfect");
    callDisplay();
    
    }
}
</script>
 <apex:form id="frm">
  <apex:actionFunction action="{!Display}" name="callDisplay" rerender="frm"/>
  <apex:outputText value="Enter The Number"/>
  <apex:inputText id="Num" value="{!text}"/>
  <apex:commandButton value="Validate" onclick="DisplayErr()" />
  Sample Output:
  <apex:outputText id="out" value="{!text}"/>
 </apex:form>
</apex:page>

Try this and let me know if it works.