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

<apex:actionfunction> not Working Properly
VisualForcePage
The function is like, it takes input from the page and displays the same value in the output text in a pageblock,but my action function is not working
is der any fault in my code??
<apex:page controller="ActionController" > <script type="text/javascript"> function validate() { ClickMe(); } </script> <apex:form id="f1"> <apex:actionFunction action="{!Click}" name="ClickMe" rerender="pg"/> <apex:pageBlock id="pg"> <apex:outputLabel value="Enter Name"> <apex:inputText value="{!Name}" id="n1"/> </apex:outputLabel> <apex:commandButton value="Refresh" onclick="validate();" /> </apex:pageBlock> </apex:form> <apex:pageBlock> <apex:outputText value="{!Name1}"></apex:outputText> </apex:pageBlock> </apex:page>Controller
public class ActionController { public String Name{Get;Set;} public String Name1{Get;Set;} public PageReference Click() { Name1=Name; system.debug(Name1); return null; } }
The function is like, it takes input from the page and displays the same value in the output text in a pageblock,but my action function is not working
is der any fault in my code??
You can try the following Sample code :
VisualForcePage :
Controller :
Please mark as best answer if it helps you.
Thank you,
Ajay Dubedi
can u tell me what is the problem in my code
I did changes in VF page and Controller please look into it
didnt required to use second veriable Name1.
I run following code in my Org. its working fine.
public class ActionController {
public String Name{Get;Set;}
public String Name1{Get;Set;}
public void Click(){
//Name1=Name;
system.debug(Name1);
// return null;
}
}
VF Page:
No need to used sript. you can directly to actionfunction and button.
<apex:page controller="ActionController" >
/*<script type="text/javascript">
function validate(){
ClickMe();
}
</script>*/
<apex:form id="f1">
<apex:actionFunction action="{!Click}" name="ClickMe" rerender="pg"/>
<apex:pageBlock >
<apex:outputLabel value="Enter Name">
<apex:inputText value="{!Name}" id="n1"/>
</apex:outputLabel>
<apex:commandButton value="Refresh" onclick="ClickMe();" />
</apex:pageBlock>
<apex:pageBlock id="pg">
<apex:outputText value="{!Name}"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>
this will help for you.
Regards,
Anil
Try the below code: (this will work fine)
Due to call to js function ,the whole vf page is getting refreshed so if we return false in the onclick function it will rerender as required.
Thanks.