Reputation:
I made a HTML page with a button, that displays a message saying: "This is a message". Everything looks fine, but when I press the button don't get a message. I checked for any mistakes, but I couldn't find anything. What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<title>Testing JavaScript</title>
<link rel="stylesheet" type="css" href="Button.css">
</head>
<body>
<h1>Javascript</h1>
<p>I am testing JS on this page.<br/>
This is a button.</p>
<script>
var message = "This is a message";
function popUp()
{
alert(message);
}
</script>
<button type="button" onclick="press()">Press me!</button>
</body>
</html>
Upvotes: 0
Views: 186
Reputation: 1155
You dont have a function named as "press()" declared, change the code
<!DOCTYPE html>
<html>
<head>
<title>Testing JavaScript</title>
<link rel="stylesheet" type="css" href="Button.css">
</head>
<body>
<h1>Javascript</h1>
<p>I am testing JS on this page.<br/>
This is a button.</p>
<script>
var message = "This is a message";
function popUp()
{
alert(message);
}
</script>
<button type="button" onclick="popUp()">Press me!</button>
</body>
</html>
Upvotes: 1