Jump to content

An Issue With An External Script


Recommended Posts

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>

 <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>

</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

  • 2 weeks later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...