Emi_98 Posted October 12, 2020 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? Link to comment Share on other sites More sharing options...
Chris_Larham Posted October 26, 2020 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. Link to comment Share on other sites More sharing options...
ishan_shah Posted October 30, 2020 Share Posted October 30, 2020 add parameter in your onClick call like '().' Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now