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
Hardik ChavdaHardik Chavda 

How to call javascript functions in if condition oncomplete method?

Hi,
I have to call javascript functions oncomplete method but using if condition. Actually I can call using if condition but the issue which I'm facing is that I am not able to use controller variable for coparision in if codition. Can anyone help me with this? Following is the code.
<apex:commandButton styleClass="btn btn-primary" action="{!NextAssessment}" value="Next " oncomplete="if(!currentPos == totalQuestion){return;}else{onPageRerender();endProcess();}" onclick="startProcess();" reRender="AssessmentBody,op1,op2" />
The issue here is that in oncomplete method, I'm not able to compare those two controller variable, I guess It's not getting value from controller. Can anyone suggest me right syntex how to use "if(!currentPos == totalQuestion)" ?

"CurrentPos" and "totalQuestion" both are controller variable.
Shailendra Singh ParmarShailendra Singh Parmar
Hi Hardik,
I think, you can compare controller variables in js also if they are string or numbers. did you tried something like below
<apex:commandButton styleClass="btn btn-primary" action="{!NextAssessment}" value="Next " oncomplete="if('!currentPos}' == '{!totalQuestion}'){return;}else{onPageRerender();endProcess();}" onclick="startProcess();" reRender="AssessmentBody,op1,op2" />

if that doesn't work i would prefer to have two button but render one at a time depending on condition like below
 
<apex:commandButton styleClass="btn btn-primary" action="{!NextAssessment}" value="Next "  onclick="startProcess();" reRender="AssessmentBody,op1,op2"  rendered="{!currentPos = !totalQuestion}"/>

<apex:commandButton styleClass="btn btn-primary" action="{!NextAssessment}" value="Next " oncomplete="onPageRerender();" onclick="startProcess();" reRender="AssessmentBody,op1,op2"  rendered="{!currentPos != !totalQuestion}"/>

Thanks!