Jump to content

I have a problem to make work javascript


Fizgal

Recommended Posts

Hi everybody,

 

I am learning javascript on this website. But when I did that simple exercice in the begining, it did not work.

 

<!DOCTYPE html><html>

<head>

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

<body><script src="jvsTest.js"></script><h1>My Web Page</h1><p id="demo">A Paragraph</p><button type="button" onclick="MyFunction()">Try it</button></body></html>

 

When you go to the demo page, you click on the button and it changes from: 'A paragraph' to 'Paragraph changed'.

 

so I tried it and (I use notepad++) it didn't work. I did like above, then with javascript in the <body> section, then on a separate sheet with javascript language. Still, it didn't work.

 

As a matter of fact, I tried the other javascripts I wrote, did not work either. My browser is Firefox, I disabled the block pop up window and tried it on Explorer and Google Chrome, and nothing works. So what could be the problem?

Why it does not work?

Link to comment
Share on other sites

You should be checking your browsers error console, Firefox has a good extension called Firebug (may be bundled by default now, not sure). The issue you are likely to see is that MyFunction doesn't exist, because in your code it's defined as myFunction (notice the casing difference). In Javascript, variable / function / etc names are case sensitive.

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