Emi_98 0 Posted October 12, 2020 Report Share Posted October 12, 2020 Hello, fellow developers or learners. I was trying to implement an example I saw here: https://www.w3schools.com/js/js_whereto.asp. The script was function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed.";} . It was titled ‘File.js’ . The HTML text was <!doctype HTML> <HTML> <BODY> <h2>An External JavaScript</h2> <p ID = "demo">A paragraph</p> <button type = "BUTTON" ONCLICK = "myFunction">TRY IT</button> <script src = "content://com.estrongs.files/storage/emulated/0/JavaScript/File.js"></script> </BODY> </HTML> When I load the HTML page and I click the “Try it” button, *A paragraph* does not change to *paragraph changed*. Do you understand what I'm trying to say, please? Quote Link to post Share on other sites
Chris_Larham 0 Posted October 26, 2020 Report Share Posted October 26, 2020 Hi there, I made two changes to your HTML text, then tested it in my PHP Storm IDE and it worked - *A paragraph* successfully changed to *paragraph changed*. 1. You need to add empty parentheses after the name of the function that is called in response to a button click - i.e. "onclick="myFunction()". 2. You need to change the 'src' value of the script element, like this: "script src="https://www.w3schools.com/js/myScript.js". You should find that making those two simple changes makes your code functional; it worked for me. Quote Link to post Share on other sites
ishan_shah 2 Posted October 30, 2020 Report Share Posted October 30, 2020 add parameter in your onClick call like '().' Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.