I am pasting pseudo code


<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 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:facet name="header"><center>Material</center></apex:facet>        
                 <apex:outputText value="{!mlist.name__c}" />



          function test(){

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



**********************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'){

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

2 Answers 2


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

  • jquery is new to me so please tell me how to proceed using server side @freaker87
    – Gayathri
    Commented Nov 6, 2015 at 4:09

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

  • Did this help u?
    – freaker87
    Commented Dec 6, 2015 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .