You are here

Activity 7

24 November, 2015 - 17:10

In this activity, we will make our button respond to our mouse click by adding JavaScript to our page.

Save the files plain_button.html, popup.js and hello.html to the same folder on your local drive.

Open the file plain_button.html in your browser.

Click the button that says TALK TO ME.

  1. What happens when you click the button TALK TO ME?

Now open up the file in a text editor, such as Notepad. You will see an HTML tag called <input> in the body of the document. This is the tag that displays the button.

Add a new attribute to this tag called onClick

This will cause the pop-up window to display the contents of hello.html when the button is clicked.

onClick="javascript:popUp('hello.html')"

When you have entered this new attribute, the complete line should look like this:

<input type=button value="TALK TO ME" onClick="javascript:popUp('hello.html')">

Open the file popup.js and copy everything in it to plain_button.html.

This is the JavaScript code that will be triggered when the button is clicked.

Place all the code between the <HEAD> and </HEAD> tags in plain_button.html.

View the page in your browser and click the TALK TO ME button again.

  1. After changing the code what happens when you click the TALK TO ME button?
  2. What are the starting and ending HTML tags that enclose the JavaScript.