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
Ram Shiva KumarRam Shiva Kumar 

Java script is not working

Hi, 

i am using the external java script file from sttaicresource,  according to the code when i click on the "try it " botton  " A paragraph"  line should be changed to "Paragraph changed." but when i click on the button iam not getting any change.  Code is as follows,

VF code:
<apex:page >
<!--In case you uploaded just the file-->
<html>

<head>

<apex:includeScript value="{!URLFOR($Resource.jsss,'siva123.js')}"/>

</head>
<body>

<h1>External JavaScript</h1>

<p id="demo">A Paragraph.</p>

<button type="button" onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> myFunction is stored in an external file called "myScript.js".</p>


</body>
</html>



JS file:

function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; }


Please any body suggest mr for this.


Regards,
Siva.


</apex:page>
 
Shweta_AgarwalShweta_Agarwal
Hi Siva,

can you do Inspect element while you are clicking on button and check the console if its throwing any error. Some tyme in VF page id got replced with path id for example "Demo" can be "form:Body:demo" in that case replace your code with $['id $= demo'].val() = "Paragraph changed.".

Hope this will solve your issue.

Thanks
Rahul SharmaRahul Sharma
Your static resource path might not be correct. Try changing it.
I used the JS code in Visualforce page and it works fine:
<apex:page >
    <!--In case you uploaded just the file-->
    <html>

        <head>

        </head>
        <body>

            <h1>External JavaScript</h1>

            <p id="demo">A Paragraph.</p>

            <button type="button" onclick="myFunction()">Try it</button>

            <p><strong>Note:</strong> myFunction is stored in an external file called "myScript.js".</p>

            <script>
                function myFunction() { 
                    document.getElementById("demo").innerHTML = "Paragraph changed."; 
                }
                
            </script>

        </body>
    </html>
</apex:page>