0

I am pasting pseudo code

***********************vfpage******************************

<apex:page standardController="Movie__c" extensions="Movietable" id="p">
  <apex:form id="f">

       <apex:pageBlock title="Movie Table" id="pageblock" >
          <apex:commandButton action="{!save}" id="cb"  value="Save" onclick="test();"/>
      </apex:pageBlock>
     <apex:pageBlock id="pb1">
      <apex:pageBlockSection id="pbs" title="1st group" collapsible="false">
        <apex:dataTable id="dt" value="{!mt}" var="mlist" cellpadding="5" cellspacing="0"  width="100%">
        <apex:column id="c">
                 <apex:facet name="header"><center>Select to ADD</center></apex:facet>        
                 <apex:inputCheckbox value="{!mlist.select__c}" id="checkbox" > </apex:inputCheckbox>
                 </apex:column>          
       <apex:column >
                 <apex:facet name="header"><center>Material</center></apex:facet>        
                 <apex:outputText value="{!mlist.name__c}" />
          </apex:column>

        </apex:dataTable>     
      </apex:pageBlockSection>   

      </apex:pageblock>
      <script>

          function test(){
            addmat();          
          }
          </script>

     <apex:outputPanel id="newmaterial">
  <script>
   if('{!mtext}'=='25'){
   alert(' plese select 26);
   }   
  </script>
  </apex:outputPanel>
  <apex:actionFunction name="addmat" action="{!material}" id="newac" rerender="newmaterial"></apex:actionFunction> 


      </apex:form>

</apex:page>

**********************Apex class*******************

public class Movietable{


public List<Movie__c> mt{get;set;}
public List<Movie__c> mt1{get;set;}
public boolean m25{get;set;}
public String mtext{get;set;}
public Movietable(ApexPages.standardController stdController) {

 mt=[select id, name__c,select__c,Cinemas__c from Movie__c];

 }

 public PageReference save() { 
 mt=[select id, name__c,select__c,Cinemas__c from Movie__c];
 PageReference pr;
 pr = new PageReference('/'+opp_id);

   return null;


}
public PageReference material() { 
    Integer i=mt.size();
    for(Integer j=0;j<i;j++){
      if(mt[j].select__c==true && mt[j].name__c=='25'){
      m25=true;
      mtext='25';

   }
}
return null;


}

}

I want on clicking save button after selecting material '25',alert should come saying please select 26 and it should stay on the same page until we select 26.once 26 is selected along with 25 the record should save and navigate to opportunity detail page.

As id's are dynamically generating in original code I couldn achieve it through javascript id's so please try to give me the solution using controller.

Many thanks in advance

0

You can try using jquery so that you will not have id issues , you can start searching id ending with , contains and other selectors. This will be better if you do using client side rather than server side which will have delay in pop ups. -BK

| improve this answer | |
  • jquery is new to me so please tell me how to proceed using server side @freaker87 – Gayathri Nov 6 '15 at 4:09
0

In such case follow these steps , 1. Change commandButton to HTML button 2. In you test() while calling material action method , dont return page Reference instead return the value say 25||26 or any custom message 3. Based on that message you would know if you want to save or show an alert 4. If you want to save , call the save method

You can try js remoting as well , which will be very easy , but as pointed earlier best way is to do via javascript || jquery

Thanks BK

| improve this answer | |
  • Did this help u? – freaker87 Dec 6 '15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.