Javascript: First example

This entry is part 4 of 27 in the series Javascript Tutorial

We will work on our first example.

<!DOCTYPE html>
<html>
    <head>
        <title>First Program</title>        
    </head>
    <body>
        <h1>First JavaScript Program</h1>
        <p>Click the button to change the sentence</p>
        <p id="first">First Program</p>
        <button type="button" onclick="myFunction()">Try it</button>
        <script>
            function myFunction() {
                document.getElementById("first").innerHTML = "This is my first Javascript program";
            }
        </script>
    </body>
</html>

button

Using Webstorm editor, grab the code above and paste it into index.html.

Save the file index.html into htdocs directory inside Apache.  For my case, it is d:\Apache2.2\htdocs.

first

The htdocs directory is actually the Apache default web directory.

Now open the chrome browser and type into the URL box localhost.

first1

Series Navigation<< Javascript: Using Netbeans
Javascript: First example explanations >>

One thought on “Javascript: First example

  1. This example is too complicated for a beginner. You’ll need to point out from the beginning that a basic understanding of HTML is required.

Comments are closed.