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
Adil ShaikhAdil Shaikh 

How can we call javascript method written inside VF page from javascript button?

<apex:page showheader="false" doctype="html-5.0">
<script src="https://ap1.salesforce.com/soap/ajax/28.0/connection.js"></script>
<script src="https://ap1.salesforce.com/soap/ajax/28.0/apex.js"></script>
<apex:includeScript value="/support/console/34.0/integration.js"/>

  
<script type="text/javascript">
      
    
    function Stopfunc(){
        logic.....
    }
    
    function Startfunc(){

    }
    
    function test(){
        alert('hiii');
    }
    $(document).ready(function(){
        test();
    });   
    
</script>

 
<button onclick="Stopfunc();" id="stop_id"> Stop  </button>
<button onclick="Startfunc();" id="start_id"> Resume start </button>
</apex:page>

 

I want to call Stopfunc() and Startfunc() functions from javascript buttons.

Best Answer chosen by Adil Shaikh
VineetKumarVineetKumar
Sorry my friend but this is not possible. As is not possible in any platform apart from salesforce as well.
Javascript is a client side validation method as in layman context (at page level), and different page have different page validations.

All Answers

VineetKumarVineetKumar
What do you mean by javascript buttons?
Adil ShaikhAdil Shaikh
I mean by the javascript buttons on detail Page.
VineetKumarVineetKumar
Ok so you mean to say that you want to call apex method from the JS button,
Something like this :
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

//Call method by passing parameters 
sforce.apex.execute("<ClassName>","<MethodName>",{<parameterName>:<parameterValue>});
Replace with values between, ' < >'
Adil ShaikhAdil Shaikh
That sample code i provided dont have the controller class. Vf page only contains the java script method. which i want to call  from javascript button on detail page.
VineetKumarVineetKumar
Now I'm getting confused. So are you trying to call VF page javascript from the Detail page button javascript?
Adil ShaikhAdil Shaikh
Yes, I am trying to call Javascript functions on VF page from Details page javascript button .
VineetKumarVineetKumar
Sorry my friend but this is not possible. As is not possible in any platform apart from salesforce as well.
Javascript is a client side validation method as in layman context (at page level), and different page have different page validations.
This was selected as the best answer
Adil ShaikhAdil Shaikh
@VineetKumar Thanks for your explanation
umesh1234umesh1234
@ vineeth

I need Javascript Button In List view 

if  i select 5 opportunity from list view in pop up i want to sisplay total amount from 5 opportunity
UmmiUmmi
Friends i am using this code in My Opportunity List view,
If i click this button it is displaying selected Record Ids 
I have one amount field in opportunity i need to display(pop up) total amount from selecetd Records

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

    var records = {!GETRECORDIDS($ObjectType.Opportunity)}; 

var names=id.Name;
   
if (records[0] == null) 

alert('Please select a record'); 

else 
{

alert(names+"records is"+records);
}
UmmiUmmi
User-added image