1

In my page, the javascript coding is as follows

<script>
    function validationcomplete(){
        var strg1=document.getElementById("Endereço").value;
        var strg2=document.getElementById("Numero").value;      
        var strg1=document.getElementById("Endereço").value;
        var strg2=document.getElementById("Numero").value;
        document.getElementById("Endereço").value=strg2+" "+strg1; 

        alert("Potvrđujemo da je vaš dopis uspješno prosljeđen Službi odnosa sa strankam Dacia");
    }
</script>

I have to replace this coding with a static JS resource file. How can I do this?

  • Note that its the JavaScript that should go in the static resource so don't include the HTML script tag; that remains in your Visualforce page. – Keith C Jun 16 '15 at 7:48
1

just store this file in static resource , and after that include this in your vf page using below syntax!!!

<apex:includeScript value="{!$Resource.javascriptname}"/>
|improve this answer|||||
1

I prefer not to use <apex:includeScript> for performance reasons.

From the Visualforce Performance Best Practices guide:

Consider including JavaScript files using a standard HTML tag right before your closing tag instead

So I usually do :

<script src="{!$Resource.myscript}"></script>
|improve this answer|||||
0

What you have to do is first save the code as a separate JS file then create a new static resource in your Salesforce Org and add the JS File into the resource.Now to include the javascript code in your vf page just add this line(say your static resource is named as test)

apex:includeScript value="{! $Resource.test}"

|improve this answer|||||

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.