You need to sign in to do that
Don't have an account?
Javascript works on page but returns syntax error when uploaded as static resource
So I'm creating my first functions in Javascript for visualforce.
I started by created the script directly on the page. This works and it takes a large amount of space.
So instead I planned on creating a bunch of functions and uploading those as a static resource. Then have a single script on the page that calls the functions and sets the element id.
When everything is on the page directly it works fine. The moment I remove my functions and upload to a static resource I get a syntax error.
Here's a sample of a really simple function. It accepts to variables, multiples them, and returns the result.
<script type="text/javascript"> function TAPCalculate(UQ, UP){ var P = UQ * UP; return P; } </script>
I created this .js file and then uploaded as a static resource called 'Contract_Calcs"
My visualforce page then has an include script:
<apex:includeScript value="{!$Resource.Contract_Calcs}"/>
And then I call this function from the script on my page. I don't even get to the point of calling the function and instantly get a syntax error in firebug. Firebug states my first line of the function is wrong. That's the var P = UQ * UP;
It works on the page -- why doesn't it work when I upload it as a static resource?
javascript files do not contain script tags. Just the javascript.
All Answers
The resource contains JUST the function? No script tag or other markup????
aballard --
The resource contains the full function with script tag.
javascript files do not contain script tags. Just the javascript.
Excellent! Noob mistake. Thanks!