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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...