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

using JS from static resource from onclick javascript on custom button

I want to access some JS function defined in static resource java file from Javascript on custom button.


anybody knows how to do this? 




1. Upload you JS file(Ex:- myScript.js) in to StaticResources.

2. Give it a name(Ex:- mySample). 

3. If your JS file has a function named as "myFunction()" you can access that method in VF page as below.


<apex:includeScript value="{!$Resource.mySample}"/>


<apex:commandButton value="Click Me" onclick="myFunction();"/>





sorry for bad english used in previous query..


Actual scenario is like this..


I am creating custom button using custom buttons&links. It gives me options do link it to VF page

or S-control or Javascript which I can write on same page.


In that javascript, I want to write some JS code which will be used in more than one custom buttons.

so I wanted to refactor it. which is why I want to move this code into Static resource file. and call that

js function from every custom button javascript code..


Setup->Customize->Contact->buttons & links , in this click on New under custom buttons and Links 


I hope I am described problem clearly now. 






I actually have the same question and was wondering if you have found a solution?  Thanks!




Any ideas on how to do it ?


We ended up re-writing the javascript and setting the link to be a custom link that called an onClick javascript and passed a field value to it.  It seems to be working pretty well.  It's much easier to do it in VisualForce though using prageeth's example above.  If I had had the option of going with a VF page I would have done it that way.