+ Start a Discussion
hramanihramani 

VF page error

I have the below code where I have used if condition and wen i try to save it ,it throws the below error


Error: Syntax error


But when I remove the exclamatory mark before 'IF' it saves perfectly but the
condition is not satisfied.

I want the first window to open if the condition is true and the second if the condition is false.
Kindly help me

 

 

<apex:page showHeader="false" standardcontroller="Merchandise__c" extensions="callout1" wizard="true">


<apex:form >


<apex:pageBlock >
<apex:pageBlockButtons >
<apex:pageblockSection >
<apex:outputPanel id="panel">


<apex:commandButton value="Search" action="{!testing1}" rerender="panel" onclick="{!IF({!Merchandise__c.yoyo__c}!=null, 'window.open('/apex/twovalues?id={!idi}','','width=800,height=500')', 'alert('ShelfNo not available')')} "/>

<br/>

</apex:outputPanel>


</apex:pageblockSection></apex:pageBlockButtons> </apex:pageBlock>
</apex:form>
</apex:page>

 

 

Sagar PareekSagar Pareek

I think this is not a valid way to do this. Rather you can call a javascript function in the onclick event.
<apex:commandButton value="Search" action="{!testing1}" rerender="panel" onclick="callFunction()"/>

 

<script>

function callFunction(){

    if('{!objectname.fieldname}' == 'true') 

    {

        if( confirm('xxxxxxxxx'))

        {

             //process

        }

         else

         {

             window.location.href = '../'     + '{!objectname.Id}'

         }
 

    } 

    else

    {

       window.location.href = '../'     + '{!objectname.Id}'

    } 

}

 

 </script>

 

Just an idea. Try.

digamber.prasaddigamber.prasad

 

Hi,

 

Is this javascript error, if yes, then you have to use escape character something like below:-

 

<apex:commandButton value="Search" action="{!testing1}" rerender="panel" onclick="{!IF({!Merchandise__c.yoyo__c}!=null, 'window.open(\'/apex/twovalues?id={!idi}\',\'\','width=800,height=500\')', 'alert(\'ShelfNo not available\')')} "/>

 Let me know if you have any issue.

 

Happy to help you!

 

 

AnushaAnusha

<apex:commandButton value="Search" action="{!testing1}" rerender="panel" onclick="{!IF(Merchandise__c.yoyo__c !=null, 'window.open(\'/apex/twovalues?id={!idi}\',\'\',\'width=800,height=500\')', 'alert(\'ShelfNo not available\')')} "/>

sandeep@Salesforcesandeep@Salesforce

You are using it in wrong way . First exclaimatory sign take care of all merge fields you use inside it so you don't need to use this sign again beofore fieds separately.

digamber.prasaddigamber.prasad

As per suggestion from Sandeep, your button should be:-

 

<apex:commandButton value="Search" action="{!testing1}" rerender="panel" onclick="{!IF(Merchandise__c.yoyo__c!=null, 'window.open(\'/apex/twovalues?id={!idi}\',\'\','width=800,height=500\')', 'alert(\'ShelfNo not available\')')} "/>

 Let me know if you have any question.