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
PremanathPremanath 

How To write code for save & Cancel operation done in one button

Hi guys,

When we click on button it should save some functionality and then close that window.

How to write code for this functionality.

 

At least tell me cancel functionality using controller.

 

Thanks a lot,

Best Answer chosen by Admin (Salesforce Developers) 
PremanathPremanath

Hi guys,

Finally i found that

 

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton action="{!save}" value="Save" rerender="AJAXTest" status="AJAXStatus"/>
<apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" ID="AJAXStatus"/>&nbsp;&nbsp;
<apex:commandButton value="cancel" oncomplete="window.top.close();"/>
</div>
</apex:form>

All Answers

JitendraJitendra

Hi,

Use command button to save the information and call the method of Controller. After sucessfull execution call the javascript method to close the window.

 

<apex:page>

<!-- Your code  -->
<apex:commandButton oncomplete="closeWin" action="{!save}" value="Save" id="theButton"/>

<script type="text/javascript">
/* Close Current window after Save */
function closeWin()
{
  self.close();
}
</script>

</apex:page>

 

PremanathPremanath

Hi jithendra thanks for you reply 

 

It's not working ,

 

There is one javascript button is there when we click on that button one popup window came i.e one VF page.

I have return code in that vf page but it's not working

plz cheak it.

 

<apex:page controller="commentspage" showHeader="false" sidebar="false" showChat="false" standardStylesheets="false" >

<script type="text/javascript">
function closeWin(){
self.close();
}
</script>

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton oncomplete="closeWin" action="{!save}" value="Save" id="theButton"/>
</div>
</apex:form>
</apex:page>

 

JitendraJitendra

Hi,

Van you provide me your complete code.

 

The code, which i have provided should be written in Popup Window.

 

 

PremanathPremanath

Hi ,

Javascript button code is this,

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

 

var url="/apex/commentspage?&id= {!Contact.Id}";

newWin=window.open(url, 'Popup','height=500,width=600,left=150,top=150,resizable=yes,scrollbars=no,toolbar=no,status=no');

if (newWin.focus())
{
newWin.focus();

}

 

 

After creation of button.

Go with contact record, there is one button available right,

Then click on that button one VF page popup window came.

The VF page is.. 

<apex:page controller="commentspage" showHeader="false" sidebar="false" showChat="false" standardStylesheets="false" >

<script type="text/javascript">
function closeWin(){
self.close();
}
</script>

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton oncomplete="closeWin" action="{!save}" value="Save" id="theButton"/>
</div>
</apex:form>
</apex:page>

 

 

The Action performed on controller...

Please solve my problm...

 

 

 

 

PremanathPremanath

Hi guys,

Finally i found that

 

<apex:form > <br/><br/>
<div align="center">
<apex:inputTextarea value="{!CommentText}"/><br/><br/>
<apex:commandButton action="{!save}" value="Save" rerender="AJAXTest" status="AJAXStatus"/>
<apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" ID="AJAXStatus"/>&nbsp;&nbsp;
<apex:commandButton value="cancel" oncomplete="window.top.close();"/>
</div>
</apex:form>

This was selected as the best answer